struct Foo

{

char *pName;

char *pAddress;

};

main()

{

struct Foo *obj = malloc(sizeof(struct Foo));

clrscr();

obj->pName = malloc(100);

obj->pAddress = malloc(100);

strcpy(obj->pName,"Your Name");

strcpy(obj->pAddress, "Your Address");

free(obj);

printf("%s", obj->pName);

printf("%s", obj->pAddress);

}

a. Your Name, Your Address

b. Your Address, Your Address

c. Your Name Your Name

d. None of the above

Answers were Sorted based on User's Feedback



struct Foo { char *pName; char *pAddress; }; main() { struct Foo *obj =..

Answer / guest

d) printd Nothing, as after free(obj), no memory is there
containing

obj->pName & pbj->pAddress

Is This Answer Correct ?    6 Yes 1 No

struct Foo { char *pName; char *pAddress; }; main() { struct Foo *obj =..

Answer / sankara subramanian.n

ya, free(ob); mean free(delete) a previous block of memory .so structure contained item has been deleted

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More C Code Interview Questions

main() { printf("\nab"); printf("\bsi"); printf("\rha"); }

3 Answers  


main() { main(); }

1 Answers  


const int perplexed = 2; #define perplexed 3 main() { #ifdef perplexed #undef perplexed #define perplexed 4 #endif printf("%d",perplexed); } a. 0 b. 2 c. 4 d. none of the above

1 Answers   emc2, HCL,


int main() { int x=10; printf("x=%d, count of earlier print=%d", x,printf("x=%d, y=%d",x,--x)); getch(); } ================================================== returns error>> ld returned 1 exit status =================================================== Does it have something to do with printf() inside another printf().

2 Answers  


main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcat(a,b)); } a. Hello b. Hello World c. HelloWorld d. None of the above

3 Answers   HCL,






main() { float f=5,g=10; enum{i=10,j=20,k=50}; printf("%d\n",++k); printf("%f\n",f<<2); printf("%lf\n",f%g); printf("%lf\n",fmod(f,g)); }

1 Answers  


Is the following code legal? typedef struct a aType; struct a { int x; aType *b; };

1 Answers  


/*what is the output for*/ void main() { int r; printf("Naveen"); r=printf(); getch(); }

4 Answers  


#include<stdio.h> #include<conio.h> void main() { int a=(1,2,3,(1,2,3,4); switch(a) { printf("ans:"); case 1: printf("1");break; case 2: printf("2");break; case 3: printf("1");break; case 4: printf("4");break; printf("end"); } getch(); }

0 Answers  


Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.

1 Answers  


why java is platform independent?

13 Answers   Wipro,


#include<stdio.h> main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }

1 Answers  


Categories