[Solved] C# – ref this (reference to self)

[ad_1] You don’t need to use ref in your parameter declarations. For reference types like your class A, a parameter declared as just A other will cause C# to pass a reference to the object. A parameter declared as A other in C# is similar to A* other in C++. A parameter declared as ref … Read more

[Solved] Why my function doesn’t work?

[ad_1] Your exponent function needs to return the n instead of x and in your main() you probably want to initialize the variable x to the value of function exponent with an argument of 5: int x = exponent(5); prior to printing via: print_exponent(x); That being said, your exponent function is broken as the return … Read more

[Solved] nested calls to printf [duplicate]

[ad_1] You may be able to see what’s happening more clearly if you split the statement into several statements: int temp1 = printf(“Hello world!\n”); int temp2 = printf(“%d”, temp1); printf(“%d”, temp2); The first printf prints Hello world!\n. Since this is 13 characters, it returns 13. The second printf prints 13. Since this is 2 characters, … Read more

[Solved] Positive and negative number values [duplicate]

[ad_1] One way would be to just add a negative sign in front of the value: int myInt = -myInt; Another way to switch between a positive or negative number in a statement would be to multiply it by -1. myInt = myInt * -1; 0 [ad_2] solved Positive and negative number values [duplicate]

[Solved] If/Else Statements in C are not working

[ad_1] This: if(fare == -40){ char desc[50] = “Ouch! Cold either way!!”; } opens up a new scope, with a new local variable called desc, that “shadows” the one in the surrounding scope. This variable is initialized to the string, then thrown away as the scope exits. The variable of the same name in the … Read more

[Solved] CreateThread() does not work [closed]

[ad_1] You didn’t post any minimal compiling code we can help you debug, so, everything I’m about to say are guesses based on other questions I’ve seen on this topic: make sure asd is declared static, CreateThread is a C function and knows nothing about class methods make sure asd is declared __stdcall, having wrong … Read more

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

[ad_1] #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]); } … Read more

[Solved] What will be the output in C? [duplicate]

[ad_1] Warning, long winded answer ahead. Edited to reference the C standard and to be clearer and more concise with respect to the question being asked. The correct answer for why you have 32 has been given a few times. Explaining the math using modular arithmetic is completely correct but might make it a little … Read more

[Solved] Difference between & and * [duplicate]

[ad_1] &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 … Read more

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

[ad_1] 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 … Read more