C Programming Quiz: Practice Exam!

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Vedant Two
V
Vedant Two
Community Contributor
Quizzes Created: 1 | Total Attempts: 401
| Attempts: 401 | Questions: 50
Please wait...
Question 1 / 50
0 %
0/100
Score 0/100
1. Library function pow() belongs to which header file?

Explanation

The library function pow() belongs to the math.h header file. This header file provides various mathematical functions, including the pow() function, which is used to calculate the power of a number. Therefore, to use the pow() function in a program, the math.h header file needs to be included.

Submit
Please wait...
About This Quiz
C Programming Quiz: Practice Exam! - Quiz

This C Programming Quiz: Practice Exam tests understanding of C syntax and functions, assessing skills through code snippets and problem-solving scenarios. Ideal for learners aiming to enhance their... see moreprogramming acumen. see less

2. How many loops are there in C?

Explanation

In the C programming language, there are three types of loops: the for loop, the while loop, and the do-while loop. These loops allow the program to repeat a block of code multiple times based on a specified condition. Therefore, the correct answer is 3, as there are three loops in C.

Submit
3. Who developed C languages?

Explanation

Dennis Ritchie developed the C programming language. He created C in the early 1970s at Bell Labs, along with his colleague Ken Thompson. C became widely popular due to its simplicity, efficiency, and portability, and it played a significant role in the development of modern operating systems and software. Ritchie's contributions to the field of computer science extend beyond C, as he also co-developed the Unix operating system and made significant contributions to the development of the programming language B, which preceded C.

Submit
4. What is the output of the below program? int main() { int i,j,k,count; count=0; for(i=0;i<5;i++) {    for(j=0;j<5;j++)    {       count++;    } } printf("%d",count); return 0; }

Explanation

The program uses nested for loops to iterate through two variables, i and j, both ranging from 0 to 4. Within the inner loop, the count variable is incremented by 1 each time. Since the inner loop is executed 5 times for each iteration of the outer loop, the count variable is incremented a total of 25 times. Therefore, the output of the program is 25.

Submit
5. What is the meaning of the below lines? void sum (int, int);  

Explanation

The correct answer is "sum is a function which takes two int arguments and returns void." This is because the given lines "void sum (int, int);" indicate the declaration of a function named "sum" that takes two integer arguments and returns nothing (void).

Submit
6. The concept of two functions with same name is known as?

Explanation

Function overloading is the concept of having multiple functions with the same name but different parameters. This allows programmers to define multiple functions with the same name but with different behaviors based on the type and number of arguments passed to them. This helps in writing more concise and readable code by providing a single name for similar operations that can be performed on different data types or with different parameter combinations.

Submit
7. What is the length null string?

Explanation

The length of a null string is 0 because a null string does not contain any characters. Therefore, it has no length or size.

Submit
8. In the given below code, the P2 is [Typedef int *ptr;

Explanation

The correct answer is "Integer pointer" because the code snippet defines a typedef for a pointer to an integer. This means that the variable P2 will be a pointer that can hold the memory address of an integer variable.

Submit
9. What is the output of the below program? int main() { int i,j,count; count=0; for(i=0; i<5; i++); {      for(j=0;j<5;j++);     {         count++;     } } printf("%d",count); return 0; }

Explanation

The program contains two nested for loops. The first loop iterates from 0 to 4, and the second loop also iterates from 0 to 4. However, both loops have a semicolon immediately after the condition, which means that the loops are empty and do not have any statements inside them. Therefore, the count variable is incremented only once outside the loops, resulting in a value of 1. This value is then printed as the output.

Submit
10. Which of the following has a global scope in the program?

Explanation

Macros have a global scope in a program. Macros are preprocessor directives that are defined using the #define statement and are replaced with their corresponding values during the preprocessing stage. Since macros are defined at the global level and can be accessed from anywhere in the program, they have a global scope. On the other hand, formal parameters, constants, and local variables have a limited scope and are only accessible within their respective functions or blocks.

Submit
11. What is the following is an invalid header file in C?

Explanation

not-available-via-ai

Submit
12. #include<stdio.h> int main()  { usigned int i= 65535;/*Assume 2byte integer*/  While(i++! =0)  printf("%d", ++i); printf("\n"); return 0; }

Explanation

The code starts with the variable i initialized to 65535. The while loop condition checks if i incremented by 1 is not equal to 0. Since i is initially 65535, the condition is true and the loop is entered. Inside the loop, i is incremented again before being printed. This process continues indefinitely, incrementing i and printing it until it reaches the maximum value for an unsigned integer (65535) and then wraps around to 0. Therefore, the loop will continue infinitely, printing the numbers from 0 to 65535 repeatedly.

Submit
13. Out of the following declarations, which one is invalid?

Explanation

The declaration "long short d = 40;" is invalid because there is no data type called "long short" in C++. The "long" and "short" keywords cannot be used together in a declaration.

Submit
14. #include<stdio.h> int main(){    int count, temp, i, j, number[30];    printf("How many numbers are u going to enter?: ");    scanf("%d",&count);    printf("Enter %d numbers: ",count);    for(i=0;i<count;i++)    scanf("%d",&number[i]);    for(i=count-2;i>=0;i--){       for(j=0;j<=i;j++){         if(number[j]>number[j+1]){            temp=number[j];            number[j]=number[j+1];            number[j+1]=temp;         }       }    }    printf("Sorted elements: ");    for(i=0;i<count;i++)       printf(" %d",number[i]);    return 0; }

Explanation

The given code is implementing the bubble sort algorithm. It takes input from the user, stores it in an array, and then uses nested loops to compare and swap adjacent elements if they are in the wrong order. This process is repeated until the array is sorted in ascending order. Finally, the sorted elements are printed. Therefore, the correct answer is "bubble sort".

Submit
15.  #include<stdio.h> void main()  { int I=65; char J='A'; if(I==J)  { printf("hey"); } else { printf("hii"); } }

Explanation

The code compares the integer value 65 with the ASCII value of the character 'A', which is also 65. Since the values are equal, the condition in the if statement is true, and "hey" is printed.

Submit
16. #include<stdio.h> main()  { printf(3+"Good morning "); }

Explanation

The code snippet uses pointer arithmetic to print the string "Good morning " starting from the third character. The pointer arithmetic `3+"Good morning "` moves the pointer forward by 3 characters, skipping the first 3 characters "Goo". Therefore, it prints "d morning".

Submit
17. When C Language was invented?

Explanation

C Language was invented in 1972.

Submit
18. #include<stdio.h> int main()  { int a[5]={5,1,15,20,25}; int i,j,m; i= ++a[1]; j= a[1]++; m= a[i++]; printf("%d%d%d", i,j,m) ; return 0; }

Explanation

The code initializes an array "a" with values {5, 1, 15, 20, 25}.

The variable "i" is assigned the value of the second element of the array (1) after incrementing it by 1, so i becomes 2.

The variable "j" is assigned the value of the second element of the array (1), and then the value of the second element is incremented by 1, so j becomes 1.

The variable "m" is assigned the value of the element at index i (2), which is 15. Then, the value of i is incremented by 1, so i becomes 3.

Finally, the values of i, j, and m are printed, resulting in the output: 3, 2, 15.

Submit
19.  #include<stdio.h> void main()  { int I; for(I=1;I<=5;I++)  { if(I==3)  { break; } printf("%d",I); }}

Explanation

The code includes a for loop that iterates from 1 to 5. Inside the loop, there is an if statement that checks if the value of I is equal to 3. If it is, the break statement is executed, which terminates the loop. Therefore, when I is equal to 3, the loop is stopped and the program moves on to the next line of code after the loop. Before the break statement is executed, the printf statement is executed, which prints the value of I. So, the output will be 1 2.

Submit
20.  #include<stdio.h> int xstrlen(char *s) {    int length = 0;        while(*s!='\0')    {length++; s++;}    return (length); }    int main() {    char d[] = "DATASTRUCTURE";         printf("Length = %d\n", xstrlen(d));    return 0; }

Explanation

The given code calculates the length of a string using the xstrlen function. The function iterates through the characters of the string until it reaches the null character '\0', incrementing the length variable each time. In the main function, a string "DATASTRUCTURE" is passed to the xstrlen function, and the returned length is printed. Since the string has 13 characters, including the null character, the code returns the length 13.

Submit
21. What will be the output of the following C code? #include <stdio.h> int main() { printf("%d ", 1); goto l1; printf("%d ",2); } void foo() { l1 : printf("3 ", 3); }

Explanation

The code will result in a compilation error because the label "l1" is defined inside the function "foo" and cannot be accessed outside of it. Therefore, the "goto" statement in the main function will not be able to find the label "l1" and will result in a compilation error.

Submit
22. Libray function getch() belongs to which header file?

Explanation

The correct answer is conio.h. The conio.h header file is used in C programming language to provide console input/output functions. The getch() function is one of the functions provided by this header file, which is used to read a single character directly from the console without echoing it.

Submit
23. Which of the following ways is correct to include the header file in the C program?

Explanation

Both A and B are correct ways to include the header file in a C program.

In option A, "#include" is used to include the standard input/output header file. This is the most commonly used way to include header files in C programs.

In option B, "#include"stdio.h"" is used to include the same header file. This method is used when the header file is located in the current directory or a specific directory relative to the current directory.

Both methods achieve the same result of including the specified header file in the C program.

Submit
24. What is the default return type of a function?

Explanation

The default return type of a function is "int". This means that if a function does not explicitly specify a return type, it will default to returning an integer value.

Submit
25. Which bitwise operator is suitable for turning off a the particular bit in a number?

Explanation

The & operator is suitable for turning off a particular bit in a number. This operator performs a bitwise AND operation between two operands. When used with a specific bit pattern, it can be used to turn off a particular bit by setting it to 0 while leaving the other bits unchanged.

Submit
26. Which of the following functions can be used to increase the size of dynamically allocated array?

Explanation

The realloc() function can be used to increase the size of a dynamically allocated array. It allows for the reallocation of memory for an existing block, which means that it can be used to resize an array by allocating more memory for it. This function takes two arguments: a pointer to the previously allocated memory block and the new size in bytes. It returns a pointer to the newly allocated memory block, which can be used to access the resized array.

Submit
27.  Predict the output of the following code segment:  
int main()
{
int array[10] = {3, 0, 8, 1, 12, 8, 9, 2, 13, 10};
int x, y, z;
x = ++array[2];
y = array[2]++;
z = array[x++];
printf("%d %d %d", x, y, z);
return 0;
}

Explanation

The code segment initializes an array with 10 elements. The variable 'x' is assigned the value of the third element in the array after incrementing it. The variable 'y' is assigned the value of the third element in the array before incrementing it. The variable 'z' is assigned the value of the element in the array at index 'x' after incrementing 'x'. Finally, the values of 'x', 'y', and 'z' are printed, which are 10, 9, and 10 respectively.

Submit
28.  Predict the output of the following code segment:  
int main()
{
int number1 = -17;
int number2 = -5;
int result = number1 % number2;
printf("%d",result);
return 0;
}
 

Explanation

The code segment calculates the remainder when number1 is divided by number2 using the modulus operator (%). In this case, number1 is -17 and number2 is -5. When -17 is divided by -5, the remainder is -2. Therefore, the output of the code segment is -2.

Submit
29.  #include<stdio.h> Void main()  { While(! printf("while loop is amazing one") ; }

Explanation

The given code will result in a compilation error. This is because the condition inside the while loop is not a valid expression. The printf() function returns the number of characters printed, so using it as a condition in the while loop is not valid syntax.

Submit
30. Which of the following % operation is invalid?

Explanation

The % operator in Java is used to find the remainder of a division operation. It can be used with integers, longs, and floats. However, it cannot be used with floats directly. In the given options, all the other operations are valid except for 2 % 4f. This is because the % operator cannot be used with floats, so 2 % 4f is an invalid operation.

Submit
31. What is the output of the below program? int main() { const int a = 10; printf("%d",++a); return 0; }  

Explanation

The program is trying to increment the value of a, which is declared as a constant using the "const" keyword. Constants cannot be modified once they are assigned a value. Therefore, attempting to increment a constant variable will result in a compilation error.

Submit
32.  Associativity of unary operator is from _________ to __________.

Explanation

The associativity of unary operators is from right to left. This means that if there are multiple unary operators in a single expression, they will be evaluated from right to left. For example, in the expression "-5!", the unary operator "-" is evaluated first, followed by the factorial operator "!".

Submit
33. Which of the following operator has lowest precedence amongst all the operators ?

Explanation

The comma operator has the lowest precedence among all the operators. This means that it has the least priority when it comes to evaluating expressions. The comma operator allows multiple expressions to be evaluated sequentially, from left to right, and the value of the entire expression is the value of the rightmost expression. It is commonly used in for loops or function calls where multiple expressions need to be evaluated in a specific order.

Submit
34. #include <stdio.h> void c( int[] ); int main() { int ary[4] = {1, 2, 3, 4}; c(ary); printf("%d ", ary[0]); } void c(int p[4]) { int i = 1; p = &i; printf("%d ", p[0]); }

Explanation

The correct answer is "1 1".

In the main function, an array "ary" is declared and initialized with values {1, 2, 3, 4}. The function "c" is then called with the array "ary" as the argument.

In the "c" function, a local variable "i" is declared and assigned the value 1. The parameter "p" is then assigned the address of "i". The statement "printf("%d ", p[0]);" prints the value at the memory location pointed to by "p", which is 1.

Back in the main function, the statement "printf("%d ", ary[0]);" prints the value at the first index of the array "ary", which is also 1.

Submit
35. #include<stdio.h> int main()  { int x; For(x= -1;x<=10;x++)  { if(x<5)  Continue; else break; printf("abc"); } return 0; }

Explanation

The code starts with initializing the variable x to -1. Then, it enters a for loop that runs as long as x is less than or equal to 10. Inside the loop, there is an if condition that checks if x is less than 5. If it is, the loop continues to the next iteration. If it is not, the loop breaks and the program exits the loop. However, the printf statement that prints "abc" is placed after the break statement, so it will never be executed. Therefore, the correct answer is 0 times.

Submit
36.  #include<stdio.h> main()  { int n=8; int f(int n); printf("%d", f(n)); } int f(int n)  { if(n>0)  return (n+f(n-2)); }

Explanation

The program is using recursion to calculate the value of f(n). In the main function, n is initialized to 8 and then passed to the f function. In the f function, it checks if n is greater than 0. Since 8 is greater than 0, it returns the sum of n and f(n-2), which is f(6). This process continues until n becomes 0, at which point the recursion stops. Therefore, the final value returned by f(8) is 20.

Submit
37. #include<stdio.h> int main()  { int x=3; float y=3.0; if(x==y)  printf("x and y are not equal"); return 0; }

Explanation

In this code, the variable x is an integer with a value of 3, and the variable y is a float with a value of 3.0. The if statement compares the values of x and y using the equality operator (==). Since the values of x and y are equal, the condition of the if statement is true. Therefore, the code inside the if statement will execute, which is the printf statement that prints "x and y are equal". Hence, the correct answer is "x and y are equal".

Submit
38. #include <stdio.h> void main() { char *s= "data"; char *p = s; printf("%c%c", p[1],s[2]); }

Explanation

The code initializes a character pointer 's' to point to the string "data". Then, another character pointer 'p' is initialized to point to the same memory location as 's'. The printf statement prints the characters at index 1 of 'p' (which is 'a') and index 2 of 's' (which is 't'). Therefore, the output will be "at".

Submit
39. #include<stdio.h> int main()  { int a=500, b=100, c; if(! a>=400)  b=300; printf("b=%d c=%d \n", b, c); return 0; }

Explanation

In this code, the condition in the if statement is "! a>=400". The "!" operator is a logical negation operator, so it will negate the result of the expression "a>=400". Since a is equal to 500, the expression "a>=400" is true, and negating it will make it false. Therefore, the code inside the if statement will not be executed and the value of b will remain 100. The value of c is not initialized in the code, so it will contain garbage value. The printf statement will print "b=100 c=garbage".

Submit
40. #include<stdio.h> #include<conio.h> void main()  { printf("\n yo"); printf("\b ghost"); printf("\r hy"); getch(); }

Explanation

The given code is a C program that uses the printf function to print out strings. The program first prints " yo" which will be displayed as " yo" in the output. Then it uses the escape sequence \b to move the cursor back one position, so the next string " ghost" will overwrite the space and be displayed as " ghost". Next, it uses the escape sequence \r to move the cursor to the beginning of the line, so the next string " hy" will overwrite the previous strings and be displayed as " hy". Finally, the program waits for user input with the getch function. Therefore, the output will be "hyghost".

Submit
41.  #include <stdio.h>  int main()  {      int* data;     *data= 9;     printf("%d", *data);      return 0;  }

Explanation

The given code will result in a compilation error. This is because the pointer variable "data" has not been assigned any memory before dereferencing it using the "*" operator. This leads to undefined behavior and a compilation error.

Submit
42. #include<stdio.h> int main()  { int i=0; For(; i<=5;i++)  printf("%d", i); return 0; }

Explanation

This code snippet is a simple C program that uses a for loop to print the values of i from 0 to 5. The loop starts with i=0 and continues until i

Submit
43. What will be the ouput of this following c code? #include <stdio.h> void main() { int a[4] = {1, 2, 3,4}; int *p = a; printf("%p\t%p", p, a); }

Explanation

The code declares an integer array 'a' with 4 elements and initializes it with values 1, 2, 3, and 4. It also declares a pointer variable 'p' and assigns the address of the first element of 'a' to it. The printf statement prints the value of 'p' and 'a', which are both addresses. Since 'p' is assigned the address of the first element of 'a', both 'p' and 'a' will have the same address. Therefore, the output will be the same address printed twice.

Submit
44. #include<stdio.h> int main()  { Chat ch; if(Ch= printf(" "))  printf(" It matters \n") ; return 0; }

Explanation

The correct answer is "It doesn't Matters". In the given code, the variable "ch" is of type "Chat" which is not a valid data type in C. It should be "char" instead. Also, the if statement is assigning the value of the expression "printf(" ")" to "Ch" instead of comparing it. Since the expression inside the printf function is just a space, it will return 1 (true) and the if statement will be true. Therefore, the code will print "It matters" and the correct answer is "It doesn't Matters".

Submit
45. What is the output of this program?  #include<stdio.h> Void main()  { int a=b=c=10; a=b=c=50; printf("\n%d%d%d", a,b,c); }

Explanation

The program will result in a compile-time error because the "Void" keyword should be "void" (lowercase "v"). This error prevents the program from running correctly and producing any output.

Submit
46. Choose the invalid identifier from the below.

Explanation

The invalid identifier in the given options is "volatile". In programming, an identifier is a name used to identify a variable, function, or any other user-defined item. However, "volatile" is a valid keyword in many programming languages, used to indicate that a variable's value can be modified by external influences. It cannot be used as an identifier for naming variables or other entities.

Submit
47. #include<stdio.h> void main()  { float b=0.45; if(b<0.45)  printf("wow"); else printf ("how"); }

Explanation

The given code declares and initializes a float variable b with the value 0.45. The if statement checks if b is less than 0.45. Since b is equal to 0.45, the condition is false and the program executes the else block. Therefore, the output will be "how".

Submit
48.  #include <stdio.h> int main()  {      char a[] = { 'D, 'A', 'T', 'A' };      char* ppp = &a[0];      *ppp++; // Line 1      printf("%c %c ", *++ppp, --*ppp); // Line 2  } 

Explanation

The program initializes an array 'a' with the characters 'D', 'A', 'T', 'A'. Then, it declares a pointer 'ppp' and assigns it the address of the first element of the array.

In Line 1, the expression '*ppp++' increments the pointer 'ppp' to point to the next element in the array, but dereferences the original pointer to get the value 'D'.

In Line 2, the expression '*++ppp' increments the pointer 'ppp' again to point to the next element in the array, and then dereferences it to get the value 'T'. The expression '--*ppp' decrements the value at the current pointer location, resulting in 'D'.

Therefore, the output is 'T D'.

Submit
49. #include<stdio.h> main()  {       enum { abesit, abesec=4,akgec};       printf("%d %d", abesit, akgec); }

Explanation

The code defines an enumeration with three values: abesit, abesec, and akgec. The value of abesit is 0, abesec is 4, and akgec is 5. The printf statement then prints the values of abesit and akgec, which are 0 and 5 respectively.

Submit
50.  #include<stdio.h> #include<conio.h> void main()  { char s[]="ghost"; printf("%d",sizeof(s)); getch(); }

Explanation

The correct answer is 6. The sizeof() function in C returns the size in bytes of the variable or data type passed as an argument. In this case, the argument is the character array "s" which has a size of 5 characters. However, the sizeof() function also includes the null character '\0' at the end of the string, so the total size is 6 bytes. Therefore, the output of the printf statement is 6.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 04, 2020
    Quiz Created by
    Vedant Two
Cancel
  • All
    All (50)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Library function pow() belongs to which header file?
How many loops are there in C?
Who developed C languages?
What is the output of the below program?...
What is the meaning of the below lines? void sum (int, int);  
The concept of two functions with same name is known as?
What is the length null string?
In the given below code, the P2 is [Typedef int *ptr;
What is the output of the below program?...
Which of the following has a global scope in the program?
What is the following is an invalid header file in C?
#include<stdio.h> ...
Out of the following declarations, which one is invalid?
#include<stdio.h> ...
 #include<stdio.h> ...
#include<stdio.h> ...
When C Language was invented?
#include<stdio.h> ...
 #include<stdio.h> ...
 #include<stdio.h> ...
What will be the output of the following C code?...
Libray function getch() belongs to which header file?
Which of the following ways is correct to include the header file in...
What is the default return type of a function?
Which bitwise operator is suitable for turning off a...
Which of the following functions can be used to increase the size of...
 Predict the output of the following code segment:...
 Predict the output of the following code segment:...
 #include<stdio.h> ...
Which of the following % operation is invalid?
What is the output of the below program?...
 Associativity of unary operator is from _________ to __________.
Which of the following operator has lowest precedence amongst all the...
#include <stdio.h> ...
#include<stdio.h> ...
 #include<stdio.h> ...
#include<stdio.h> ...
#include <stdio.h> ...
#include<stdio.h> ...
#include<stdio.h> ...
 #include <stdio.h>  ...
#include<stdio.h> ...
What will be the ouput of this following c code?...
#include<stdio.h> ...
What is the output of this program? ...
Choose the invalid identifier from the below.
#include<stdio.h> ...
 #include <stdio.h> ...
#include<stdio.h>...
 #include<stdio.h> ...
Alert!

Advertisement