Welcome to C Programming Quiz, Randomly Selected !!

Question 1. The following program releases memory from a link list..which of the following is true?
struct node *nPtr, *sPtr;    /* pointers for a linked list. */ 
for (nPtr=sPtr; nPtr; nPtr=nPtr->next)
{    
    free(nPtr);
}

It will work correctly since the for loop covers the entire list.

It may fail since each node "nPtr" is freed before its next address can be accessed.

In the for loop, the assignment "nPtr=nPtr->next" should be changed to "nPtr=nPtr.next".

The loop will never end.

Question 2. In the following code, the P2 is Integer Pointer or Integer?
typedef int *ptr;
ptr p1, p2;

integer

integer pointer

error in declaration

none of the above

Question 3. What is the purpose of fflush() function.

flushes all streams and specified streams.

flushes only specified stream.

flushes input/output buffer.

flushes file buffer.

Question 4. what is the output of the following sample code?
void myFunc (int x) 
{ 
   if (x > 0)
   myFunc(--x); 
   printf("%d, ", x); 
} 
int main() 
{ 
   myFunc(5); 
   return 0; 
}

1, 2, 3, 4, 5, 5,

4, 3, 2, 1, 0, 0,

0, 0, 1, 2, 3, 4,

0, 1, 2, 3, 4, 5,

Question 5. struct customer *ptr = malloc( sizeof( struct customer ) );
Given the sample allocation for the pointer "ptr" found above, which one of the following statements is used to reallocate ptr to be an array of 10 elements?

ptr = realloc( ptr, 10 * sizeof( struct customer));

realloc( ptr, 9 * sizeof( struct customer ) );

ptr = malloc( 9 * sizeof( struct customer ) );

ptr = realloc( ptr, 9 * sizeof( struct customer ) );

Question 6. What function should be used to free the memory allocated by calloc() ?

dealloc();

demalloc(variable_name, 0)

free()

decalloc(variable_name, 0)

Question 7. What are the different types of real data type in C ?

float, double

short int, double, long int

float, double, long double

double, long int, float

Question 8. Explain the following C Declaration:
typedef int *(*(*fp[])())()

fp is pointer to function returning array of pointer to int

fp is function returning pointer to array of pointer to function returning pointer to int

fp is array of pointer to function returning pointer to function returning pointer to int

fp is array of pointer to function returning pointer to pointer to int

Question 9. What number will z in the following code sample
int z,x=5,y=-10,a=4,b=2;
z = x++ - --y * b / a;

5

6

10

11

Question 10. What does the following declaration mean?
int (*ptr)[10]

ptr is array of pointers to 10 integers

ptr is a pointer to an array of 10 integers

ptr is an array of 10 integers

ptr is an pointer to array