C Programming Test

C Programming Mock Test

Free C Programming Mock Test: Placement

Practice the free Online C Programming Test to get success in future placement. This online mock test will help you in the time of final placements.

General Instructions:
1. Each Programming test contains 15 questions.
2. Total allotted time is 20 minutes for each test.
3. No negative marking.
4. Try to finish it on time.
5. The Test will be submitted automatically if the time expired.
6. Don’t refresh the page.

Join us on Telegram... Members
0%

C Programming Test 1

1 / 15

The modulus operator cannot be used with a long double.

2 / 15

In a function two return statements should never occur.

3 / 15

How many bytes are occupied by near, far and huge pointers (DOS)?

4 / 15

Point out the error in the program?


#include

int main()

{

struct a

{

  float category:5;

char scheme:4;

};

printf(“size=%d”, sizeof(struct a));

return 0;

}


 

5 / 15

Can we specify a variable filed width in a scanf() format string?

6 / 15

If malloc() successfully allocates memory it returns the number of bytes it has allocated.

7 / 15

Are the following declarations same?


char far *far *scr;

char far far** scr;


 

8 / 15

What will be the output of the program?


#include<stdio.h>

#include<math.h>

int main()

{

printf(“%f\n”, sqrt(36.0));

return 0;

}


 

9 / 15

In a macro call the control is passed to the macro.

10 / 15

Which of the following function sets first n characters of a string to a given character?

11 / 15

If the size of pointer is 4 bytes then What will be the output of the program ?


#include

int main()

{

char *str[] = {“Frogs”, “Do”, “Not”, “Die”, “They”, “Croak!”};

printf(“%d, %d”, sizeof(str), strlen(str[0]));

return 0;

}


 

12 / 15

What will be the output of the program (myprog.c) given below if it is executed from the command line?

cmd> myprog friday tuesday sunday

/* myprog.c */

#include

int main(int argc, char *argv[])

{

printf(“%c”, *++argv[1]);

return 0;

13 / 15

Point out the error in the program (in Turbo-C).

#include

#define MAX 128

int main()

{

const int max=128;

char array[max];

char string[MAX];

array[0] = string[0] = ‘A’;

printf(“%c %c\n”, array[0], string[0]);

return 0;

}


 

14 / 15

What will be the output of the program?

#include<stdio.h>

int main()

{

int i;

char c;

for(i=1; i<=5; i++)

{

scanf(“%c”, &c); /* given input is ‘a’ */

printf(“%c”, c);

ungetc(c, stdin);

}

return 0;

}

15 / 15

Which of the following statements are correct about an if-else statements in a C-program?

1 Every if-else statement can be replaced by an equivalent statements using   ?: operators
2 Nested if-else statements are allowed.
3 Multiple statements in an if block are allowed.
4 Multiple statements in an else block are allowed.

 

Your score is

The average score is 35%

0%

0%

C Programming Test 2

1 / 15

short integer is at least 16 bits wide and a long integer is at least 32 bits wide

2 / 15

In which order do the following gets evaluated

1 Relational
2 Arithmetic
3 Logical
4 Assignment

3 / 15

What will be the output of the program?


#include<stdio.h>

#define SQUARE(x) x*x

int main()

{

float s=10, u=30, t=2, a;

a = 2*(s-u*t)/SQUARE(t);

printf(“Result = %f”, a);

return 0;

}


 

4 / 15

A float occupies 4 bytes. If the hexadecimal equivalent of these 4 bytes are A, B, C and D, then when this float is stored in memory in which of the following order do these bytes gets stored?

5 / 15

What will be the output of the program ?


#include

#include

int main()

{

char str1[20] = “Hello”, str2[20] = ” World”;

printf(“%s\n”, strcpy(str2, strcat(str1, str2)));

return 0;

}


 

6 / 15

What will be the output of the program ?

#include<stdio.h>

 

int main()

{

union var

{

int a, b;

};

union var v;

v.a=10;

v.b=20;

printf(“%d\n”, v.a);

return 0;

}

7 / 15

Can we have an array of bit fields?

8 / 15

What will be the output of the program?


#include<stdio.h>

int main()

{

unsigned int res;

res = (64 >>(2+1-2)) & (~(1<<2));

printf(“%d\n”, res);

return 0;

}


 

9 / 15

Which of the following cannot be checked in a switch-case statement?

10 / 15

Which of the following statements are correct about the program?


#include<stdio.h>

int main()

{

int x = 30, y = 40;

if(x == y)

printf(“x is equal to y\n”);

 

else if(x > y)

printf(“x is greater than y\n”);

 

   else if(x < y)

printf(“x is less than y\n”)

return 0;

}


 

11 / 15

Macros have a local scope

12 / 15

Is this a correct way for NULL pointer assignment?

int i=0;
char *q=(char*)i;

13 / 15

What will be the output of the program ?


#include<stdio.h>

#include<string.h>

int main()

{

char sentence[80];

int i;

printf(“Enter a line of text\n”);

gets(sentence);

for(i=strlen(sentence)-1; i >=0; i–)

putchar(sentence[i]);

return 0;

}


 

14 / 15

Point out the error in the program?


struct emp

{

int ecode;

struct emp *e;

};


 

15 / 15

In Turbo C/C++ under DOS if we want that any wild card characters in the command-line arguments should be appropriately expanded, are we required to make any special provision?

Your score is

The average score is 35%

0%

0%

C Programming Test 3

1 / 15

We can modify the pointers “source” as well as “target”.

2 / 15

What do the following declaration signify?
void *cmp();

3 / 15

What will be the output of the program?


#include<stdio.h>

int get();

int main()

{

const int x = get();

printf(“%d”, x);

return 0;

}

int get()

{

return 20;

}


 

4 / 15

Which of the following statements correct about the below program?


#include<stdio.h>

int main()

{

union a

{

int i;

char ch[2];

};

union a u1 = {512};

union a u2 = {0, 2};

return 0;

}


1 u2 CANNOT be initialized as shown.
2 u1 can be initialized as shown.
3 To initialize char ch[] of u2 ‘.’ operator should be used.
4 The code causes an error ‘Declaration syntax error’

5 / 15

Is there any difference int the following declarations?
int fun(int arr[]);
int fun(int arr[2]);

6 / 15

Point out the error in the program


#include

int main()

{

int i;

#if A

printf(“Enter any number:”);

scanf(“%d”, &i);

#elif B

printf(“The number is odd”);

  return 0;

}


 

7 / 15

What will be the output of the program?


#include<stdio.h>

#include<math.h>

int main()

{

float n=1.54;

printf(“%f, %f\n”, ceil(n), floor(n));

return 0;

}


 

8 / 15

Point out the correct statements are correct about the program below?


#include<stdio.h>

int main()

{

char ch;

while(x=0;x<=255;x++)

printf(“ASCII value of %d character %c\n”, x, x);

  return 0;

}


 

9 / 15

What will be the output of the program?


#include<stdio.h>

int main()

{

    const c = -11;

    const int d = 34;

    printf(“%d, %d\n”, c, d);

    return 0;

}


 

10 / 15

What will be the output of the program?


#include<stdio.h>

int main()

{

    const c = -11;

    const int d = 34;

    printf(“%d, %d\n”, c, d);

    return 0;

}


 

11 / 15

The program will generate infinite loop. When an EOF is encountered fgetc()returns EOF. Instead of checking the condition for EOF we have checked it for NULL. so the program will generate infinite loop.

The maximum combined length of the command-line arguments including the spaces between adjacent arguments is

12 / 15

What will be the output of the program ?


#include<stdio.h>

int main()

{

    FILE *ptr;

    char i;

    ptr = fopen(“myfile.c”, “r”);

    while((i=fgetc(ptr))!=NULL)

        printf(“%c”, i);

    return 0;

}


 

13 / 15

What will be the output of the program ?


#include<stdio.h>

int main()

{

    enum status {pass, fail, absent};

    enum status stud1, stud2, stud3;

    stud1 = pass;

    stud2 = absent;

    stud3 = fail;

    printf(“%d %d %d\n”, stud1, stud2, stud3);

    return 0;

}


 

14 / 15

Will the printf() statement print the same values for any values of a ?


#include<stdio.h>

int main()

{

float a;

scanf(“%f”, &a);

printf(“%f\n”, a+a+a);

printf(“%f\n”, 3*a);

return 0;

}


 

15 / 15

Which of the following is the correct order of evaluation for the below expression?
z = x + y * z / 4 % 2 – 1

Your score is

The average score is 38%

0%

0%

C Programming Test 4

1 / 15

We can modify the pointers “source” as well as “target”.

2 / 15

What will be the output of the program (myprog.c) given below if it is executed from the command line?
cmd> myprog one two three

/* myprog.c */

#include<stdio.h>

#include<stdlib.h>

int main(int argc, char **argv)

{

printf(“%s\n”, *++argv);

return 0;

}

3 / 15

In a file contains the line “I am a boy\r\n” then on reading this line into the array str using fgets(). What will str contain?

4 / 15

A preprocessor directive is a message from programmer to the preprocessor

5 / 15

In the expression a=b=5 the order of Assignment is NOT decided by Associativity of operators

6 / 15

What will be the output of the program?


#include<stdio.h>

int main()

{

  int i=2;

printf(“%d, %d\n”, ++i, ++i);

return 0;

}


 

7 / 15

How many times the while loop will get executed if a short int is 2 byte wide?


#include<stdio.h>

int main()

{

int j=1;

while(j <= 255)

{

printf(“%c %d\n”, j, j);

j++;

}

return 0;

}


 

8 / 15

va_list is an array that holds information needed by va_arg and va_end

9 / 15

The first argument to be supplied at command-line must always be count of total arguments.

10 / 15

Bit fields CANNOT be used in union.

11 / 15

If char=1, int=4, and float=4 bytes size, What will be the output of the program ?


#include<stdio.h>

int main()

{

char ch = ‘A’;

printf(“%d, %d, %d”, sizeof(ch), sizeof(‘A’), sizeof(3.14f));

    return 0;

}


 

12 / 15

Which of the following statements are correct about an array?

1 The array int num[26]; can store 26 elements.
2 The expression num[1] designates the very first element in the array.
3 It is necessary to initialize the array at the time of declaration.
4 The declaration num[SIZE] is allowed if SIZE is a macro.

13 / 15

What will be the output of the program?


#include<stdio.h>

int main()

{

  int k, num=30;

k = (num>5 ? (num <=10 ? 100 : 200): 500);

printf(“%d\n”, num);

return 0;

}


 

14 / 15

The keyword used to transfer control from a function back to the calling function is

15 / 15

Which of the statements is correct about the program?


#include<stdio.h>

int main()

{

float a=3.14;

  char *j;

j = (char*)&a;

printf(“%d\n”, *j);

return 0;

}


 

Your score is

The average score is 41%

0%

0%

C Programming Test 5

1 / 15

Which statement will you add in the following program to work it correctly?


#include<stdio.h>

int main()

{

printf(“%f\n”, log(36.0));

return 0;

}


 

2 / 15

What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?


#include<stdio.h>

int main()

{

int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

printf(“%u, %u, %u\n”, a[0]+1, *(a[0]+1), *(*(a+0)+1));

return 0;

}


 

3 / 15

What will be the output of the program in 16-bit platform (Turbo C under DOS) ?


#include<stdio.h>

int main()

{

printf(“%d, %d, %d”, sizeof(3.0f), sizeof(‘3’), sizeof(3.0));

return 0;

}


 

4 / 15

A structure can contain similar or dissimilar elements

5 / 15

What will be the output of the program if value 25 given to scanf()?

#include<stdio.h>

int main()

{

  int i;

printf(“%d\n”, scanf(“%d”, &i));

   return 0;

}

6 / 15

What will be the output of the program (sample.c) given below if it is executed from the command line (turbo c under DOS)?
cmd> sample Good Morning

/* sample.c */

#include<stdio.h>

int main(int argc, char *argv[])

{

printf(“%d %s”, argc, argv[1]);

return 0;

}

7 / 15

Even if integer/float arguments are supplied at command prompt they are treated as strings.

8 / 15

Data written into a file using fwrite() can be read back using fscanf()

9 / 15

What will be the output of the program?

#include<stdio.h>

int main()

{

int i=-3, j=2, k=0, m;

m = ++i && ++j || ++k;

printf(“%d, %d, %d, %d\n”, i, j, k, m);

  return 0;

}

10 / 15

If the size of integer is 4bytes, What will be the output of the program?

#include<stdio.h>

int main()

{

    int arr[] = {12, 13, 14, 15, 16};

printf(“%d, %d, %d\n”, sizeof(arr), sizeof(*arr), sizeof(arr[0]));

    return 0;

}

11 / 15

What will be the output of the program ?

#include<stdio.h>

int main()

{

int i;

char a[] = “\0”;

if(printf(“%s”, a))

printf(“The string is empty\n”);

else

printf(“The string is not empty\n”);

return 0;

}

12 / 15

If a char is 1 byte wide, an integer is 2 bytes wide and a long integer is 4 bytes wide then will the following structure always occupy 7 bytes?


struct ex

{

char ch;

int i;

long int a;

};


 

13 / 15

What will be the output of the program

#include<stdio.h>

void fun(int);

int main(int argc)

{

printf(“%d “, argc);

fun(argc);

return 0;

}

void fun(int i)

{

if(i!=4)

main(++i);

}

14 / 15

Can I increase the size of dynamically allocated array?

15 / 15

What will be the output of the program (in Turbo C under DOS)?

#include<stdio.h>

int main()

{

char huge *near *far *ptr1;

char near *far *huge *ptr2;

char far *huge *near *ptr3;

printf(“%d, %d, %d\n”, sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));

return 0;

}

Your score is

The average score is 41%

0%

error: Content is protected !!
Top MNC's are hiring Apply Now
+ +