Welcome to C Programming Quiz, Randomly Selected !!

Question 1. The function crash(), defined below, triggers a fault in the memory management hardware for many architectures. Which one of the following explains why "got here" may NOT be printed before the crash?
void crash (void) 
{ 
 printf("got here"); 
 *((char *) 0) = 0; 
}

The C standard says that dereferencing a null pointer causes undefined behavior. This may explain why printf() apparently fails.

printf() always buffers output until a newline character appears in the buffer. Since no newline was present in the format string, nothing is printed.

If the standard output stream is buffered, the library buffers may not be flushed before the crash occurs.

printf() expects more than a single argument. Since only one argument is given, the crash may actually occur inside printf(), which explains why the string is not printed. puts() should be used instead.

Question 2. Which bitwise operator is suitable for turning on a particular bit in a number?

&& operator

|| operator

& operator

| operator

Question 3. what is the output of the following program
#include "stdio.h"
int f(int *a, int n)
{
    if (n <= 0) return 0;
    else if (*a % 2 == 0) return *a +  f(a + 1, n-1);
    else return *a - f(a + 1, n-1);
}

int main()
{
    int a[] = {12, 7, 13, 4, 11, 6};
    printf("%d", f(a, 6));
    return 0;
}

-9

5

15

19

Question 4. Identify which of the following are declarations
1:   extern int x;
2:   float square ( float x ) { ... }
3:   double pow(double, double);

1

2

1 and 3

3

Question 5. What does x mean in this code sample ?
typedef char (*(*arrfptr[3])())[10];
arrfptr x;

x is a pointer

x is an array of three pointer

x is an array of three function pointers

error in declaration of x

Question 6. Which of the following function is correct that finds the length of a string?

int xstrlen(char *s) { int length=0; while(*s!='\0') { length++; s++; } return (length); }

int xstrlen(char s) { int length=0; while(*s!='\0') length++; s++; return (length); }

int xstrlen(char *s) { int length=0; while(*s!='\0') length++; return (length); }

int xstrlen(char *s) { int length=0; while(*s!='\0') s++; return (length); }

Question 7. Can you combine the following two statements into one?
char *p;
p = (char*) malloc(100);

char p = *malloc(100);

char *p = (char) malloc(100);

char *p = (char*)malloc(100);

char *p = (char *)(malloc*)(100);

Question 8. 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 9. What will the function rewind() do?

Reposition the file pointer to a character reverse.

Reposition the file pointer stream to end of file.

Reposition the file pointer to begining of that line.

Reposition the file pointer to begining of file.

Question 10. Which of the following operations can be performed on the file "NOTES.TXT" using the below code?
FILE *fp;
fp = fopen("NOTES.TXT", "r+");

reading

writing

appending

read and write