[Solved] Adjacency List for Graphs in C

Your program is causing memory leak. You should use an array of ADI*, not an array of ADI, to store what is returned from adjancencyList(). Using subscripting looks better than incrementing in this case. One more tips is that A = &( A[0] ); does virtually nothing. Also note that they say you shouldn’t cast … Read more

[Solved] Malloc , Realloc , Memset : Struct pointers , arrays of char, int

Error was in v_push_back implementation : v->e_array = check_a(memcpy((void*)((char*)v->e_array + (v->no_e * v->e_sz)) ,new_val, v->e_sz)); //pointer has not to be saved check_a(memcpy((void*)((char*)v->e_array + (v->no_e * v->e_sz)) ,new_val, v->e_sz)); Because memcpy returns a pointer , in this case, to the last element of the array so we would have lost access to all previous memory solved … Read more

[Solved] I want to know something about pointers in C

++ has a higher precedence (meaning it binds to p tighter) than * therefore *p++ is equivalent to *(p++). Something similar to this is the difference between *p[] and (*p)[]. [] has a higher precedence than * therefore *p[] is equivalent to *(p[]) which makes a list a pointers but something like (*p)[] explicitly says … Read more

[Solved] Pointer C Language [closed]

What does this function do? It concatenates two strings, i.e. it’s doing the same as the standard strcat function. See https://man7.org/linux/man-pages/man3/strcat.3.html Assume the input is “Hello World”. Just when the function is called, some where in memory it looks like: String1: Hello\0 ^ | s1 String2: World\0 ^ | s2 Now this part while (*s1 … Read more

[Solved] How are pointers stored in memory?

C11, 6.3.2.3, paragraphs 5 and 6: An integer may be converted to any pointer type. Except as previously specified, the result is implementation-defined, might not be correctly aligned, might not point to an entity of the referenced type, and might be a trap representation. Any pointer type may be converted to an integer type. Except … Read more

[Solved] Double pointer as argument to function

Your example is basically equivalent to this: void changeString(string **strPtr) { strPtr = new string*[1]; *strPtr = new string(“hello”); //cout << strPtr[0][0]; } int main() { string *strPtr; changeString(&strPtr); //cout << strPtr[0]; return 0; } And that is basically equivalent to this: void changeString(string *strPtr) { strPtr = new string(“hello”); // Changes the pointer, not … Read more

[Solved] Pointer making C program to crash

First line: You create a pointer variable to a char, then you initialize it to address zero (NULL pointer). Second line: you try to write a zero to the address where pointer is pointing to. Address zero is outside of your process’ writable virtual memory area, so you get a segmentation fault. solved Pointer making … Read more

[Solved] c++ pointer void function issue [closed]

circleType::setRadius; double radius = circle.getRadius; The first line doesn’t do anything. The second line tries to set a variable of type double equal to a function. Perhaps you want to call these functions? This is what non-operator member function calls look like in C++: double area = circle.areaCir(radius); double circumferance = circle.circumCir(radius); circle.printCir(circumferance, area); So … Read more