Code Wiz Fin
-
Upload
jagan-nathan -
Category
Documents
-
view
27 -
download
4
description
Transcript of Code Wiz Fin
1. What is wrong with this program : main() { char *p,*q; p=(char *)malloc(25); q=(char*) malloc(25); strcpy(p,"amazon" ); strcpy(q,"hyd"); strcat(p,q); printf("%s",p); }
2. what is the output of for(;0;) printf("\n guess");
3. What will be the output? Explain.
main()
{
int i=3;
switch(i)
{
default:printf( "zero");
case 1: printf("one" );
break;
case 2:printf("two" );
break;
case 3: printf("three" );
break;
} }
4. What is the error in this snippet?
main()
{
extern int i;
i=20;
printf("%d", i);
}
5. What is the output & explain
main()sturct date {char name[20];int age ;float sal;};sturct data d ={"rajesh"};printf("%d%f",d.age,d.sal);}
6. What is the error?main(){int j=10;switch(j){ case 20:pritnf("Less than 20");break;case 30:printf("Less than 30");break;default:printf("hello");}
7. What will be the output & explain.
main(){int i;if(i=0) //it,s assisnment not logical operatorprintf(" Hell ");elseprintf("Heaven");}
8. What looks wrong with these programs?
a)#include <stdio.h>#include <stdlib.h>main(){int i;for (i=0; i<10; i=i+1) if (i<2) printf("%d is less than 2\n",i); printf("and %d is not equal to, 2 either\n",i);}
b)main(){int i; i = 0; while (i < 10); i = i + 1; printf("Finished. i = %d\n",i);}
c)#include <stdio.h>#include <stdlib.h>main(){int i;for (i=0; i<10; i=i+1) switch(i){
case 0: printf("i is 0\n"); case 1: printf("i is 1\n"); default: printf("i is more than 1\n"); }}
d)
#include <stdio.h>#include <stdlib.h>main(){int i; i=3; i=i+2*i++; printf("i is now %d\n",i);}
e)if (foo) if (bar) win (); else lose ();