- 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 following code snippet?
#include<stdio.h>
main()
{
short unsigned int i = 0;
printf("%u\n", i--);
}
Answer : A
Explanation
0, with post decrement operator value of the variable will be considered as the expressions value and later gets decremented.
Q 2 - What is the output of the following program?
#include<stdio.h>
main()
{
struct { int x;} var = {5}, *p = &var;
printf("%d %d %d",var.x,p->x,(*p).x);
}
Answer : A
Explanation
5 5 5, the two possible ways of accessing structure elements using pointer is by using -> (arrow operator) OR *.
Q 3 - First operating system designed using C programming language.
Answer : C
Explanation
UNIX. C actually invented to write an operation system called UNIX. By 1973 the entire UNIX OS is designed using C.
Q 4 - What is the output of the following program?
#include<stdio.h>
void f()
{
static int i = 3;
printf("%d ", i);
if(--i) f();
}
main()
{
f();
}
Answer : B
Explanation
As the static variable retains its value from the function calls, the recursion happens thrice.
Q 5 - What is the output of the following program?
#include<stdio.h>
void main()
{
char *s = "C++";
printf("%s ", s);
s++;
printf("%s", s);
}
Answer : B
Explanation
After s++, s points the string ++.
Q 6 - Turbo C in 16 bit DOS OS, the correct range of long double is,
Answer : B
Explanation
Explanation: The integral and precession value varies depending upon the number of bytes designated for a particular data type.
Q 7 - For a structure, if a variable behave as a pointer then from the given below operators which operator can be used to access data of the structure via the variable pointer?
Answer : C
Explanation
For a structure, Dot(.) operator can be used to access the data using normal structure variable and arrow (->)can be used to access the data using pointer variable.
Q 8 - In the given below code, the functionfopen()uses "r"to open the file source.txt in binary mode for which purpose?
#include<stdio.h>
int main ()
{
FILE *fp;
fp = fopen("source.txt", "r");
return 0;
}
Answer : A
Explanation
To open a file in C programming, we can use library function fopen(). In the given above code, fopen() function is opening a file source.txt for reading. Here, r stands for reading. If, fopen() function does not find any file for reading, returns NULL
#include<stdio.h>
int main ()
{
FILE *fp;
fp = fopen("source.txt", "r");
return 0;
}
Q 9 - An operation with only one operand is called unary operation.
B - An operation with two operand is called unary operation
C - An operation with unlimited operand is called unary operation
Answer : A
Explanation
Unary operator acts on single expression.
Q 10 - If, the given below code finds the length of the string then what will be the length?
#include<stdio.h>
int xstrlen(char *s)
{
int length = 0;
while(*s!='\0')
{length++; s++;}
return (length);
}
int main()
{
char d[] = "IndiaMAX";
printf("Length = %d\n", xstrlen(d));
return 0;
}
Answer : B
Explanation
Here, *s is char pointer that holds character string. To print whole string we use printf("%s",s) by using base address. s contains base address (&s[0]) and printf will print characters until '\0' occurs. *s only gives first character of input string, but s++ will increase the base address by 1 byte. When *s=='\0' encountered, it will terminate loop.
#include<stdio.h>
int xstrlen(char *s)
{
int length = 0;
while(*s!='\0')
{length++; s++;}
return (length);
}
int main()
{
char d[] = "IndiaMAX";
printf("Length = %d\n", xstrlen(d));
return 0;
}