Logo 
Search:

C Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C ProgrammingRSS Feeds

C programming practical question 158

  Shared By: Adah Miller    Date: Jan 24    Category: C Programming    Views: 66

Answer:

What is wrong with the following code?


int *foo()
{
int *s = malloc(sizeof(int)100);
assert(s != NULL);
return s;
}


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.

Share: 
 

Didn't find what you were looking for? Find more on C programming practical question 158 Or get search suggestion and latest updates.


Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: