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 C 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.

0%

C Programming Test 1

1 / 15

Are the following declarations same?


char far *far *scr;

char far far** scr;


 

2 / 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;

}


 

3 / 15

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

4 / 15

What will be the output of the program?


#include

#include

int main()

{

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

return 0;

}


 

5 / 15

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

6 / 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;

}


 

7 / 15

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

8 / 15

What will be the output of the program?

#include

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; }

9 / 15

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

10 / 15

The modulus operator cannot be used with a long double.

11 / 15

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

12 / 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;

}


 

13 / 15

In a function two return statements should never occur.

14 / 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;

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

Can we have an array of bit fields?

2 / 15

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

3 / 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;

}


 

4 / 15

What will be the output of the program?


#include

#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;

}


 

5 / 15

What will be the output of the program ?


#include

#include

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;

}


 

6 / 15

Is this a correct way for NULL pointer assignment?

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

7 / 15

What will be the output of the program ?

#include

 

int main()

{

union var

{

int a, b;

};

union var v;

v.a=10;

v.b=20;

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

return 0;

}

8 / 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?

9 / 15

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

10 / 15

In which order do the following gets evaluated

1 Relational
2 Arithmetic
3 Logical
4 Assignment

11 / 15

What will be the output of the program?


#include

int main()

{

unsigned int res;

res = (64 >>(2+1-2)) & (~(1<<2)); printf(“%d\n”, res);

return 0;

}


 

12 / 15

Which of the following statements are correct about the program?


#include

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;

}


 

13 / 15

Point out the error in the program?


struct emp

{

int ecode;

struct emp *e;

};


 

14 / 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?

15 / 15

Macros have a local scope

Your score is

The average score is 38%

0%

0%

C Programming Test 3

1 / 15

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

2 / 15

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


#include

int main()

{

float a;

scanf(“%f”, &a);

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

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

return 0;

}


 

3 / 15

What will be the output of the program ?


#include

int main()

{

    FILE *ptr;

    char i;

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

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

        printf(“%c”, i);

    return 0;

}


 

4 / 15

What will be the output of the program?


#include

int get();

int main()

{

const int x = get();

printf(“%d”, x);

return 0;

}

int get()

{

return 20;

}


 

5 / 15

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

6 / 15

What will be the output of the program?


#include

int main()

{

    const c = -11;

    const int d = 34;

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

    return 0;

}


 

7 / 15

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


#include

int main()

{

char ch;

while(x=0;x<=255;x++) printf(“ASCII value of %d character %c\n”, x, x);

  return 0;

}


 

8 / 15

What will be the output of the program?


#include

int main()

{

    const c = -11;

    const int d = 34;

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

    return 0;

}


 

9 / 15

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

10 / 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

11 / 15

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

12 / 15

What will be the output of the program?


#include

#include

int main()

{

float n=1.54;

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

return 0;

}


 

13 / 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;

}


 

14 / 15

Which of the following statements correct about the below program?


#include

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’

15 / 15

What will be the output of the program ?


#include

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;

}


 

Your score is

The average score is 37%

0%

0%

C Programming Test 4

1 / 15

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

2 / 15

A preprocessor directive is a message from programmer to the preprocessor

3 / 15

Bit fields CANNOT be used in union.

4 / 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.

5 / 15

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

6 / 15

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


#include

int main()

{

char ch = ‘A’;

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

    return 0;

}


 

7 / 15

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

8 / 15

What will be the output of the program?


#include

int main()

{

  int k, num=30;

k = (num>5 ? (num <=10 ? 100 : 200): 500); printf(“%d\n”, num);

return 0;

}


 

9 / 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?

10 / 15

What will be the output of the program?


#include

int main()

{

  int i=2;

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

return 0;

}


 

11 / 15

Which of the statements is correct about the program?


#include

int main()

{

float a=3.14;

  char *j;

j = (char*)&a;

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

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 one two three

/* myprog.c */

#include

#include

int main(int argc, char **argv)

{

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

return 0;

}

13 / 15

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

14 / 15

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

15 / 15

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


#include

int main()

{

int j=1;

while(j <= 255) { printf(“%c %d\n”, j, j);

j++;

}

return 0;

}


 

Your score is

The average score is 57%

0%

0%

C Programming Test 5

1 / 15

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

#include

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;

}

2 / 15

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

3 / 15

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


#include

int main()

{

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

return 0;

}


 

4 / 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

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

{

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

return 0;

}

5 / 15

A structure can contain similar or dissimilar elements

6 / 15

What will be the output of the program ?

#include

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;

}

7 / 15

What will be the output of the program

#include

void fun(int);

int main(int argc)

{

printf(“%d “, argc);

fun(argc);

return 0;

}

void fun(int i)

{

if(i!=4)

main(++i);

}

8 / 15

Can I increase the size of dynamically allocated array?

9 / 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

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;

}


 

10 / 15

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

#include

int main()

{

  int i;

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

   return 0;

}

11 / 15

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

12 / 15

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

#include

int main()

{

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

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

    return 0;

}

13 / 15

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


#include

int main()

{

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

return 0;

}


 

14 / 15

What will be the output of the program?

#include

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;

}

15 / 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;

};


 

Your score is

The average score is 45%

0%

Introduction to C

C language was developed by Dennis M.Ritchie at the Bell Telephone Laboratories in 1972. It is a programming language known for its simplicity and efficiency. It is the best choice to start with programming as it gives you a foundational understanding of programming. C is one of the most widely used computer language. C is called mother of all programming languages and is still relevant today after more than 5 decades. The UNIX operating system is completely written in C language. The C language was formalized in 1988 by the American National Standard Institute (ANSI).

First program using C Programming

				
					#include <stdio.h>
int main() {
printf("This is my first C program");
return 0;
}

Output:
This is my first C program

				
			

The above code will give you a basic understanding about the C programming and its structure.

Advantages of C Language

  • Easy to Learn
  • Structured Programming Language
  • It can handle low level programming
  • C compiler

 Important topics to cover while learning C

  • C Basics
  • C Data types
  • C Variables
  • C Operators
  • C Functions
  • C Arrays & Strings
  • C Pointers
  • File handling and Error handling
Frequently Asked Questions

C is a general-purpose, high-level programming language used to develop operating systems, applications, games and more. It was given by Dennis M.Ritchie in 1972 at Bell Telephone laboratories.

C is a structured programming language and can be used to master other programming languages. The importance can be understood by knowing that the UNIX OS was completely written in C.

The applications of C include Operating Systems, Assemblers, Databases, Text Editors, Language Interpreters etc. C compilers are available on all the operating systems. A good expertise in C lets you to learn other languages very easily.

C is a compiled language, whereas programming languages like Python, Java and JavaScript are interpreted languages. C doesn’t support class and objects while modern languages are primarily object-oriented.

Go with the C basics and take a deep knowledge about C variables, data types in C, Tokens in C, C operators, C functions, Arrays and strings, Pointers. These topics will make you strong in C.

TNP Officer provides lots of mock tests to practice. You can find and practice a free C programming MCQ based mock test at www.tnpofficer.com

C being a general-purpose language, you can use it in different practice projects. A C programmer can pursue a successful career in embedded system development and gaming field. C language acts as a gateway to the software development field. C is an open-source language. You can also contribute to open source software development project, that will give you lot of exposure.