Select chapter



functions (3.papers)
loops (1.papers)
arrays (2.papers)
structures (3.papers)
unions (1.papers)
pointers (7.papers)
null pointers (1.papers)
strings (2.papers)
misc c concepts (1.papers)
Data structures (5.papers)
linked lists (3.papers)
trees (1.papers)
basics (5.papers)
Hide

Sponsored Links


  

c interview questions and answers

1
What is a null pointer in c? Is it same as uninitialized pointer?
  1. Null pointer points to no where. uninitialized pointers points to some garbage most of the times. null pointers can be compared for inequality with any valid address returned by malloc.
  2. Null pointer and uninitialized pointers, both points to no where. both are same.
  3. Uninitialized pointers points to no where, where as null pointers will point to a valid address in memory.
  4. uninitialized pointers point to a valid address of memory always, where as null pointer points to 0th segment of ram.
Show Answer
Share Facebook gmail Twitter
2
malloc(0):
What is the output of below C program.

#include  <stdio.h>

int main(void)
{

    int *p = malloc(0);
    if(p == NULL)
        printf("Couldn't allocate 0 bytes");
    else
        printf("allocated 0 bytes");
    return 0;
}
  1. Couldn't allocate 0 bytes
  2. allocated 0 bytes
  3. compile time error, can't pass 0 to malloc.
  4. Output can be either option 1 or option 2, we can't predict the behavior, as it is implementation dependent of malloc.
Show Answer
Share Facebook gmail Twitter
3
Is it OK to pass a null pointer or 0 to realloc() method in c?
  1. Older versions of C doesn't support it though latest versions do support it.
  2. Older versions support it, but not latest versions.
  3. In none of the versions of C it is supported.
  4. It is supported in all versions of C.
Show Answer
Share Facebook gmail Twitter
4
if a function is expecting an integer pointer in c, then can i pass a void * or null or int * to that function?
  1. yes, you can pass any of them.
  2. we can pass only int * or null.
  3. we can pass only int *.
  4. we can pass int * or null or void *, but void should have proper int pointer in it.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
6
int *p = 0;

What is the output of below C program.

#include  <stdio.h>

int main(void)
{
    int *p = 0;
    *p = 0;
    return 0;
}
  1. compile time null pointer assignment error.
  2. no error no output.
  3. none of the above
  4. run time null pointer assignment or segmentation violation error.
Show Answer
Share Facebook gmail Twitter
Read more papers :