[Solved] Variable has two values simultaneously?

Changing a const-value yields undefined behaviour, and the “mysterious” output is just such undefined behaviour. It is actually needless to investigate on why a behaviour in the world of undefined behaviour is as it is then. But in your case it is probably not using a as you declare it as const, so the compiler … Read more

[Solved] How to free() my variables [closed]

You can introduce another parameter to count the elements in freeme. bool parse(bool b1, int i, int *j, int *e, char **ptr, int q, char **pString, char *str, char **freeme, int *freeme_len) { for (*e = 0; *(ptr + q + *e); (*e)++) { b1 = true; if (*(ptr + *e + q)) { str … Read more

[Solved] C++ Function Prototype? [closed]

bool doit(int list[], int size); The function doit takes an array of integers as first parameter, and the size of the array (which is an integer) as second parameter. It returns a boolean (true or false). This sort of function prototype is typically used to access each element of the array within a for loop … Read more

[Solved] What does the this pointer mean? [duplicate]

‘this’ usually refers to the instance of the object that calls a particular method of a class,union,structure or a function. when you have same names for different variables, then ‘this’ is used to differentiate between them. class stu { int roll_no; string name; public: void input(int roll_no,string name) { name=this->name; roll_no=this->roll_no; } } stu obj=new … Read more

[Solved] Convert double * to double [9] in C [closed]

#include <stdio.h> #include <string.h> typedef struct dbl9 { double array[9]; } Dbl9; Dbl9 fun(double *in){ Dbl9 ret; memcpy(ret.array, in, sizeof(ret.array));//There can be no assurance that <in> the correct return ret; } int main(){ double array[9] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; Dbl9 dbl9= fun(array); int i; for(i=0;i<9;++i){ printf(“%f\n”, dbl9.array[i]); } return … Read more

[Solved] Difference between & and * [duplicate]

&p gets the pointer to the integer p -> That is, the memory address in which p is stored. *p “dereferences” the pointer, i.e. looks at the object at the memory address provided by p and returns that object. Your code above is invalid C, as you cannot dereference an int: error: indirection requires pointer … Read more

[Solved] How can you use structures in modular programming?

Well, this is a problem: fillwordnr(f,p[].ptrletter,p[].numbers,lines,nrofline,a,c,string[]); You have to specify which element of p you want to work with – p[0], p[1], p[i], etc. Assuming nrofline is a valid index for p, you would write fillwordnr( f, p[nrofline].ptrletter, p[nrofline].numbers, lines, nrofline, a, c, string ); Honestly, based on the code you’ve posted, it’s not clear … Read more

[Solved] Pointers and addresses?

Accessing an uninitialized variable results in undefined behaviour. It may be that the program simply printed whatever garbage value was previously in that space in memory. Since C was meant to be a clean and efficient language, it doesn’t automatically fill in a value, it simply allocates an amount of memory. This section of memory … Read more

[Solved] pointers not read correctly

i intentionally left the previous answer because understanding memory allocation is trivial in programming in c specially. and as i see you have a big issue with that. but still you have issue in nearly every thing. in my actual answer, i will try to simplify you how to use strtok, to split string and … Read more