C
Programming and Technical
Programming
What will the following program do?
void main()
{
int i;
char a[]="String";
char *p="New Sring";
char *Temp;
Temp=a;
a=malloc(strlen(p) + 1);
strcpy(a,p); //Line number:9//
p = malloc(strlen(Temp) + 1);
strcpy(p,Temp);
printf("(%s, %s)",a,p);
free(p);
free(a);
} //Line number 15//
a) Swap contents of p & a and print:(New string, string)
b) Generate compilation error in line number 8
c) Generate compilation error in line number 5
d) Generate compilation error in line number 7
e) Generate compilation error in line number 1
Read Solution (Total 5)
-
- option b is the right answer.
non portablepointer conversion - 11 years agoHelpfull: Yes(2) No(0)
- answer is b)
because a is the base address of the array a[].
a=malloc(strlen(p) + 1)....here base address is increased by 1,which is not possible.so an error will be displayed showing lvalue required at compile time
- 10 years agoHelpfull: Yes(0) No(0)
- b) Generate compilation error in line number 8
- 10 years agoHelpfull: Yes(0) No(0)
- Option is a it's swap content
- 10 years agoHelpfull: Yes(0) No(0)
- answer is b)
because incompatible type in assignment. a is the character array.So here base address is not incremented by 1. - 10 years agoHelpfull: Yes(0) No(0)
C Other Question