- C Programming Tutorial
- C - Home
- C - Overview
- C - Features
- C - History
- C - Environment Setup
- C - Program Structure
- C - Hello World
- C - Compilation Process
- C - Comments
- C - Tokens
- C - Keywords
- C - Identifiers
- C - User Input
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Integer Promotions
- C - Constants
- C - Literals
- C - Escape sequences
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - if statement
- C - if...else statement
- C - nested if statements
- C - switch statement
- C - nested switch statements
- C - Loops
- C - While loop
- C - Functions
- C - Main Functions
- C - Return Statement
- C - Scope Rules
- C - Arrays
- C - Properties of Array
- C - Multi-Dimensional Arrays
- C - Passing Arrays to Function
- C - Return Array from Function
- C - Variable Length Arrays
- C - Pointers
- C - Pointer Arithmetics
- C - Passing Pointers to Functions
- C - Strings
- C - Array of Strings
- C - Structures
- C - Structures and Functions
- C - Arrays of Structures
- C - Pointers to Structures
- C - Self-Referential Structures
- C - Nested Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C Programming - Online Quiz
Following quiz provides Multiple Choice Questions (MCQs) related to C Programming Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.
Q 1 - What is the output of the below code snippet?
#include<stdio.h> main() { unsigned x = 5, y=&x, *p = y+0; printf("%u",*p); }
Answer : D
Explanation
5, as p holds the address of x which is y+0
Q 2 - What is the output of the following program?
#include<stdio.h> { int x = 1; switch(x) { default: printf("Hello"); case 1: printf("hi"); break; } }
Answer : B
Explanation
Hi, control reaches default-case after comparing the rest of case constants.
Q 3 - Following is the invalid inclusion of a file to the current program. Identify it.
Answer : C
Explanation
option (a) & (b) are valid. There is no such syntax or provision as in option (c).
Q 4 - What is the output of the following program?
#include<stdio.h> main() { int a[] = {10, 20, 30}; printf("%d", *a+1); }
Answer : C
Explanation
*a refers to 10 and adding a 1 to it gives 11.
Q 5 - What is the output of the following program?
#include<stdio.h> main() { char s1[50], s2[50] = "Hello"; s1 = s2; printf("%s", s1); }
Answer : C
Explanation
‘s1’ refers to base address and is constant. Hence raising to ‘lvalue’ required compile time error.
Q 6 - In the standard library of C programming language, which of the following header file is designed for basic mathematical operations?
Answer : A
Explanation
math.h is a header file in the standard library designed for basic mathematical operations
Q 7 - A bitwise operator “&” can turn-off a particular bit into a number.
Answer : A
Explanation
The bitwise AND operator “&” compares each bit of the first operand with the corresponding bit of the second operand. During comparison, if both operands bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.
Q 8 - Which of the following statement can be used to free the allocated memory?
Answer : B
Explanation
The library function free() deallocates the memory allocated by calloc(), malloc(), or realloc().
Q 9 - Which files will get closed through the fclose() in the following program?
#include<stdio.h> int main () { FILE *fs, *ft, *fp; fp = fopen("ABC", "r"); fs = fopen("ACD", "r"); ft = fopen("ADF", "r"); fclose(fp, fs, ft); return 0; }
Answer : D
Explanation
The syntax of fclose() function is wrong; it should be int fclose(FILE *stream); closes the stream. Here, fclose(fp, fs, ft); is using separator(,) which returns error by saying that extra parameter in call to fclose() function.
#include<stdio.h> int main () { FILE *fs, *ft, *fp; fp = fopen("ABC", "r"); fs = fopen("ACD", "r"); ft = fopen("ADF", "r"); fclose(fp, fs, ft); return 0; }
Q 10 - In the given below statement, what does the “pf” indicate?
int (*pf)();
Answer : A
Explanation
pf is a pointer as well holds some functions reference.