You are on page 1of 7

test 1:

printf("test %s\n", NULL); printf("test %s\n", NULL); prints: test (null) test (null) test 2: printf("%s\n", NULL); 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); }

0
of 0 votes

22

Answers

what is the output of for(;0;) printf("\n guess");

What will be the output?


main() { int i=3; switch(i) { default:printf( "zero"); case 1: printf("one" ); break; case 2:printf("two" ); break; case 3: printf("three" ); break; } } Answer : three Explanation : The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.

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..

What looks wrong with these programs?


# i < # s i m a i n ( ) { i n t f i ( < i o = 1 r 0 ; i % p s ri n t f ( " i } # i n c l u # m a i n { i n n t i ; n t

;) 1

; =

ed

m u

n i n , u mb e r } # i n c l u # m a i n ( ) { i n t f i i p s r i n t f ( " i ed d i

} # i # m a { i n f i i t l e s s " % p i r ( f t n } # # i m a i n ) ( i

s h

{ i ; n t = < = 1 i ;+ % = i } # i n c lu # i m a i n ( ) { i ; n t f e d

0 p i c : r s e s a i 1 p cas s :e default:printf("i is more than 1\n"); } } #i n c l ud e # i m a i n ( ) { i ; n t i ( f i < or = 1 0 ; c k c e h

: 0 p r

esa c */ esa c

: 1 p i r n o w } }

*/ defaul t:printf("i is more than 1\n");

# < l i s u t n c d i o .> h # i m a i n ( ) { i ; n t i = i i % n d o \ w n " , p si } # < s i t n c l u

i n { i n i * n p t o i n t e r ;

po i

tn

a= b c / s * 3 * e t= pr = % a " ( f t n i }

c o

When you have an if-else statement nested in another if statement, always put braces around the if-else. Thus, never write like this:
i fa ) r b ( e l l ose ( ; )

(the e l matches the closest ), i always like this:

s takes c a n pointers to the variables that are going to be set. The following

fragment will cause a crash


. . i ; n t s n a c

You might also like