c++ on MS VS it gives an error that on line 33 uninitialized local variable used( or see comment in code). On other compilers, code runs fine.
=====================================
#include <iostream>
using namespace std;
// Node structure w/ power and coefficient
struct Node
{
int coeff;
int pow;
struct Node *next;
};
void create(int x, int y, struct Node** temp) {
//declare structs
struct Node *a, *b;
//temp
b = *temp;
//if b null
if (b == NULL) {
a = new Node;
a->coeff = x;
a->pow = y;
*temp = a;
a->next = new Node;
a = a->next;
a->next = NULL;
}
//same as above, but do not allalocate new space
first
else {
a->coeff =
x;//<-------------------------this line that give error.
a->pow = y;
a->next = new Node;
a = a->next;
a->next = NULL;
}
}
int main()
{
return 0;
}
#include <iostream> using namespace std; // Node structure w/ power and coefficient struct Node { int coeff; int pow; struct Node *next; }; void create(int x, int y, struct Node **temp) { //declare structs struct Node *a, *b; //temp b = *temp; //if b null if (b == NULL) { a = new Node; a->coeff = x; a->pow = y; *temp = a; a->next = new Node; a = a->next; a->next = NULL; } //same as above, but do not allalocate new space first else { a = new Node; // we need to create a new node before assigning it values.. a->coeff = x;//<-------------------------this line that give error. a->pow = y; a->next = new Node; a = a->next; a->next = NULL; } } int main() { return 0; }
Get Answers For Free
Most questions answered within 1 hours.