[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

C Programming :: Dynamic Memory Allocation - Discussion

Home > C Programming > Dynamic Memory Allocation > MCQs Questions Discussion

18 / 18

What should the program below print?

void myfunc(char** param){
++param;
}
int main(){
char* string = (char*)malloc(64);
strcpy(string, "hello_World");
myfunc(&string);
myfunc(&string);
printf("%s\n", string);
return 0;
}

Ahello_World

Bello_World

Clo_World

Dllo_World

Answer: Option (Login/Signup)

Show Explanation

in second statement we are calling myfunc where we are passing the address of string.

in function myfunc we are receiving in double pointer (**param).

i.e param will point to the address of string. if you print address of string

printf("%u\n",&string) and variable param like printf("%u\n", param), both address will be same

in this function statement ++param will increment the address containing by param,

when you try to print string in main function it will print hello_world instead lo_World. if you change the statement in myfunc like ++(*param), it will print lo_World.



Asked In :: TCS

Post Your Answer Here:     

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here

Reply    
Rate This: +1 -0 +
    Report


Report Error

Please Login First Click Here