Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4
Captain X The "Node *ptr" is local to the function "insertbeg" you can't access it outside in "print" function Declare it global or pass pointer to function as parameter. Solution using global declaration: #include <iostream> using namespace std; struct Node{ int data; Node *link; }; Node *head = NULL; Node *ptr; void insertbeg (int x){ ptr = new Node(); ptr ->data =x; ptr ->link=head; head = ptr; } void print(){ cout << ptr->data; ptr=ptr->link; } int main() { insertbeg (2); insertbeg (3); print (); return 0; }
17th Oct 2019, 2:41 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar