What is wrong with the following code?

int *foo()

{

int *s = malloc(sizeof(int)100);

assert(s != NULL);

return s;

}



What is wrong with the following code? int *foo() { int *s = malloc(siz..

Answer / susie

Answer : & Explanation:

assert macro should be used for debugging and finding out
bugs. The check s != NULL is for error/exception handling
and for that assert shouldn’t be used. A plain if and the
corresponding remedy statement has to be given.

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More C Code Interview Questions

main() { extern int i; { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); } int i;

1 Answers  


#include<stdio.h> main() { FILE *ptr; char i; ptr=fopen("zzz.c","r"); while((i=fgetch(ptr))!=EOF) printf("%c",i); }

1 Answers  


write a program to count the number the same (letter/character foreg: 's') in a given sentence.

2 Answers  


Give a very good method to count the number of ones in a 32 bit number. (caution: looping through testing each bit is not a solution)

7 Answers   Microsoft,


main() { int i=5,j=6,z; printf("%d",i+++j); }

2 Answers  






why array index always strats wuth zero?

2 Answers  


main() { int i=5; printf("%d",++i++); }

1 Answers  


main ( ) { static char *s[ ] = {“black”, “white”, “yellow”, “violet”}; char **ptr[ ] = {s+3, s+2, s+1, s}, ***p; p = ptr; **++p; printf(“%s”,*--*++p + 3); }

1 Answers  


What are segment and offset addresses?

2 Answers   Infosys,


main() { int i=400,j=300; printf("%d..%d"); }

3 Answers  


Give a one-line C expression to test whether a number is a power of 2.

10 Answers   Microsoft,


Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list)

3 Answers   Disney, Google, ZS Associates,


Categories