in Education by
This question already has answers here: Can a local variable's memory be accessed outside its scope? (20 answers) How to access a local variable from a different function using pointers? (10 answers) Closed 3 years ago. I was trying to understand how pointers work in c when i came across this weird problem. Now, I wanted to build a linked list. The first thing I did was adding the add function. Once the function add a node to the last node of the list(which it does successfully) typedef struct linkedLists{ int x; struct linkedLists *next; //int (*add)(int) = add; }linkedList; void addF(linkedList *l, int y){ linkedList adder = {.x=y}; l->next = &adder; return; } int main(int argc, char** argv) { linkedList list = {.x=2,.next=NULL}; printf("%d\n",list.x); addF(&list,3); printf("%d\n",list.x); // If you comment this line the result changes to what it's //expected printf("%d\n",(*list.next).x); return (EXIT_SUCCESS); } If I run printf("%d\n",(*list.next).x); I get 3, which is desired. However, if I run printf("%d\n",list.x); printf("%d\n",(*list.next).x); I get: 2 Random number JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

Related questions

0 votes
    This question already has answers here: Closed 10 years ago. Possible Duplicate: What are the differences ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Closed 10 years ago. Possible Duplicate: What are the differences ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I was working with SOAP to access web service. my question is how to retrieve the value returned from ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    Below is a crude for-loop to illustrate what I need to do. Basically, if there are any 'Variable' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    Below is a crude for-loop to illustrate what I need to do. Basically, if there are any 'Variable' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    This question already has an answer here: Quasar framework q-select sets an object in the v-model than ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I have an issue with passing a struct definition to a function. Not an instance of a struct, but the definition. We ... (object sender, EventArgs e) { GetHeaders( MineStruct ); //...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I'm trying to make a function in c to create and return a new struct similar to a constructor in ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I have a linked list struct, i want to pass one node (another struct) pointer to a function (the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    Is there a side effect in doing this: C code: struct foo { int k; }; int ret_foo(const struct ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
0 votes
    I have a struct A that is defined as follows: typedef struct A { CvRect B; // rect int C; ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    I'm trying to PInvoke into this C++ library function: int Initialize(Callback* callback); struct Callback { ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 21, 2022 in Education by JackTerrance
0 votes
    I'm trying to PInvoke into this C++ library function: int Initialize(Callback* callback); struct Callback { ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I am studying Artificial Intelligence as a module in my Computer Games Programming course and one of my tasks ... appreciated, thanks. Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    When should I use a struct rather than a class in C#?...
asked Jan 16, 2021 in Technology by JackTerrance
...