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

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

1 Answers  


int i,j; for(i=0;i<=10;i++) { j+=5; assert(i<5); }

3 Answers   Cisco, HCL,


union u { struct st { int i : 4; int j : 4; int k : 4; int l; }st; int i; }u; main() { u.i = 100; printf("%d, %d, %d",u.i, u.st.i, u.st.l); } a. 4, 4, 0 b. 0, 0, 0 c. 100, 4, 0 d. 40, 4, 0

1 Answers   HCL,


given integer number,write a program that displays the number as follows: First line :all digits second line : all except the first digit . . . . Last line : the last digit

8 Answers  


Display the time of the system and display the right time of the other country

1 Answers  






write a c program to Create employee record by taking details like name, employee id, address and phone number. While taking the phone number, take either landline or mobile number. Ensure that the phone numbers of the employee are unique. Also display all the details

2 Answers   TCS,


main() { int *j; { int i=10; j=&i; } printf("%d",*j); }

9 Answers   HCL, Wipro,


how can i search an element in an array

2 Answers   CTS, Microsoft, ViPrak,


Is there any difference between the two declarations, 1. int foo(int *arr[]) and 2. int foo(int *arr[2])

1 Answers  


write a origram swaoing valu without 3rd variable

2 Answers  


main() { int i = 100; clrscr(); printf("%d", sizeof(sizeof(i))); } a. 2 b. 100 c. 4 d. none of the above

5 Answers   HCL,


Give a oneline C expression to test whether a number is a power of 2?

25 Answers   EA Electronic Arts, Google, Motorola,


Categories