Documente Academic
Documente Profesional
Documente Cultură
printf("%s\n", NULL); prints Segmentation fault (core dumped) what is the difference in the above tests ? Why is segmentation fault not thrown in test 1 above ?
0
of 0 votes
32
Answers
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); }
of 0 votes
22
Answers
What s the error in this snippet. main() { extern int i; i=20; printf("%d", i); }
What is the o/p explain. main() { float me = 1.1; double you = 1.1; if(me==you) printf("I love U"); else printf("I hate U"); }
find the error .. main() { float me = 1.1; double you = 1.1; if(me==you) printf("I love U"); else printf("I hate U");
main() sturct date { char name[20]; int age ; float sal; }; sturct data d ={"rajesh"}; printf("%d%f",d.age,d.sal); } tell the output & explain
9.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"); } 15.main() { int i; if(i=0) //it,s assisnment not logical operator printf(" Hell "); else printf("Heaven"); } Output & explain..
#include <stdio.h> #include <stdlib.h> main() { int i; for (i=0; i<10; i=i+1); printf("i is %d\n",i); } #include <stdio.h> #include <stdlib.h> main() { int numbers[10]; int i; for (i=1;i<=10;i++) numbers[i]=i; for (i=1;i<=10;i++) printf("numbers[%d]=%d\n", i, numbers[i]); } #include <stdio.h> #include <stdlib.h> main() { int i; for (i=0; i<10; i=i+1) if (i=2) printf("i is 2\n"); else printf("i is not 2\n"); } #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); } #include <stdio.h> #include <stdlib.h>
main() { int i; i = 0; while (i < 10); i = i + 1; printf("Finished. i = %d\n",i); } #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"); } } #include <stdio.h> #include <stdlib.h> main() { int i; for (i=0; i<10; i=i+1) /* check the value of i*/ switch(i){ /* is i 0? case 0: printf("i is 0\n"); break; /* is i 1? case 1: printf("i is 1\n"); break; /* now the default case */ default: printf("i is more than 1\n"); } } #include <stdio.h> #include <stdlib.h> main() { int i; i=3;
i=i+2*i++; printf("i is now %d\n",i); } #include <stdio.h> int main() { int a,b,c; int *pointer; c = 3; pointer = &c; /* divide c by itself */ a = c/*pointer; b = c /* set b to 3 */; printf("a=%d, b=%d\n", a,b); }
When you have an if-else statement nested in another if statement, always put braces around the if-else. Thus, never write like this:
if (foo) if (bar) win (); else lose ();