- C - Home
- C - Overview
- C - Features
- C - History
- C - Standards
- C - Environment Setup
- C - Program Structure
- C - Hello World
- C - Compilation Process
- C - Comments
- C - Basic Syntax
- C - User Input
- C - printf Function
- C - Format Specifiers
- Lexical Elements in C
- C - Tokens
- C - Keywords
- C - Identifiers
- Variables and Constants
- C - Variables
- C - Constants
- C - Const Qualifier
- C - Linkage
- Data Types and Type Conversions
- C - Data Types
- C - Literals
- C - Escape Sequences
- C - Booleans
- C - Integer Promotions
- C - Character Arithmetic
- C - Type Conversion
- C - Type Casting
- Operators in C
- C - Operators
- C - Arithmetic Operators
- C - Unary Operators
- C - Relational Operators
- C - Logical Operators
- C - Bitwise Operators
- C - Assignment Operators
- C - Increment and Decrement Operators
- C - Ternary Operator
- C - sizeof Operator
- C - Operator Precedence
- C - Miscellaneous Operators
- Decision Making & Control Statements
- C - Decision Making
- C - if Statement
- C - if...else Statement
- C - if...else if Ladder
- C - Nested if Statements
- C - Switch Statement
- C - Nested Switch Statements
- C - Switch Case Using Range
- Loops in C
- C - Loops
- C - For Loop
- C - While Loop
- C - Do...while Loop
- C - For Loop vs While Loop
- C - Nested Loop
- C - Infinite Loop
- C - Break Statement
- C - Continue Statement
- C - Goto Statement
- Functions in C
- C - Functions
- C - Function Prototype
- C - Main Function
- C - Function call by Value
- C - Function call by reference
- C - Nested Functions
- C - Variadic Functions
- C - User-Defined Functions
- C - Callback Function
- C - Return Statement
- C - Recursion
- C - Predefined Identifier __func__
- Scope Rules in C
- C - Scope Rules
- C - Static Variables
- C - Global Variables
- Arrays in C
- 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 - Dynamic Arrays
- Strings in C
- C - Strings
- C - Array of Strings
- C - Character Arrays
- C - Special Characters
- Pointers in C
- C - Pointers
- C - Initialization of Pointer Arrays
- C - Applications of Pointers
- C - Dereference Pointer
- C - NULL Pointer
- C - void Pointer
- C - Const Pointers & Pointer to Const
- C - Dangling Pointers
- C - Pointer Arithmetics
- C - Pointers and Arrays
- C - Pointer vs Array
- C - Pointer to an Array
- C - Array of Pointers
- C - Pointers vs. Multi-dimensional Arrays
- C - Pointer to Pointer
- C - Chain of Pointers
- C - Character Pointers and Functions
- C - Passing Pointers to Functions
- C - Return Pointer from Functions
- C - Function Pointers
- C - Array of Function Pointers
- C - Pointers to Structures
- C - Near, Far and Huge Pointers
- C - Restrict Keyword
- User-Defined Data Types
- C - Structures
- C - Structures and Functions
- C - Arrays of Structures
- C - Self-Referential Structures
- C - Dot (.) Operator
- C - Lookup Tables
- C - Enumeration (or enum)
- C - Structure Padding and Packing
- C - Nested Structures
- C - Anonymous Structure and Union
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Flexible Array Members in Structures
- C - Structures vs Unions
- Memory Management in C
- C - Memory Layout
- C - Memory Management
- C - Memory Address
- C - Storage Classes
- C - Dynamic Array Resizing
- C - Memory Leaks
- File Handling in C
- C - File Handling
- C - Input & Output
- C - File Operations
- C - Formatted Output
- C - getc, getchar, getch, getche
- Preprocessors in C
- C - Preprocessors
- C - Pragmas
- C - Macros
- C - Working of Preprocessor
- C - Preprocessor Operators
- C - Header Files
- C - Custom Header Files
- Miscellaneous Topics
- C - Error Handling
- C - Variable Arguments
- C - Command Execution
- C - Math Functions
- C - Static Keyword
- C - Random Number Generation
- C - Command Line Arguments
- C Programming Resources
- C - Questions & Answers
- C - Quick Guide
- C - Cheat Sheet
- C - Useful Resources
- C - Discussion
- C - Online Compiler
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()
{
for(1;2;3)
printf("Hello");
}
Answer : A
Explanation
infinite loop, as the second expression is non-0, hence the condition is always true.
Q 2 - What is the output of the following program?
#include<stdio.h>
main()
{
int a[] = {1,2}, *p = a;
printf("%d", p[1]);
}
Answer : B
Explanation
2, as p holds the base address then we can access array using p just like with a
Q 3 - Function fopen() with the mode "r+" tries to open the file for __
Answer : A
Explanation
Option (a), the file should exist and opens for both reading & writing.
Q 4 - What is the output of the following program?
#include<stdio.h>
main()
{
}
Answer : A
Explanation
It is valid to have main() function empty, therefore producing no displayable output.
Q 5 - What is the output of the following program?
#include<stdio.h>
main()
{
int x;
float y;
y = x = 7.5;
printf("x=%d y=%f", x, y);
}
Answer : A
Explanation
x gets the integral value from 7.5 which is 7 and the same is initialized to y.
Q 6 - A Variable name in C includes which special symbols?
Answer : D
Explanation
Characters which are allowed and not allowed with variable name,
- Underscore(_) allowed
- Capital Letters ( A Z ) allowed
- Small Letters ( a z ) allowed
- Digits ( 0 9 ) allowed
- First Charactershould bealphabet or Underscore
- Blanks & Commasnot allowed
- Special Symbols not allowed, but Underscore(_)allowed
- Reserved Word not allowed
Q 7 - Which library function can convert aninteger/longto astring?
Answer : A
Explanation
In C, ltoa() function converts long/integer data type to string data type.
char *ltoa(long N, char *str, int base);
Q 8 - What is x in the following program?
#include<stdio.h>
int main ()
{
typedef char (*(*arrfptr[3])())[10];
arrfptr x
return 0;
}
Answer : C
Explanation
Here, x is an array of three function pointers
#include<stdio.h>
int main ()
{
typedef char (*(*arrfptr[3])())[10];
arrfptr x
return 0;
}
Q 9 - Which files will get closed through thefclose()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 - extern int fun(); - The declaration indicates the presence of a global function defined outside the current module or in another file.
Answer : A
Explanation
Extern is used to resolve the scope of global identifier.