QUIZ-3 OF C PROGRAMMING LANGUAGE
Q 1 – What is the output of the following program?
#include<stdio.h>
{
int x = 1;
switch(x)
{
default: printf(“Hello”);
case 1: printf(“hi”); break;
}
}
A – Hello
B – Hi
C – HelloHi
D – Compile error
Q 2 – A macro can execute faster than a function.
A – true
B – false
Q 3 – What is the output of the following program?
#include<stdio.h>
main()
{
char *p = NULL;
printf(“%c”, *p);
}
A – NULL
B – 0
C – Compile error
D – Runtime error.
Q 4 – Which of the following functions disconnects the stream from the file pointer.
A – fremove()
B – fclose()
C – remove()
D – file pointer to be set to NULL
Q 5 – The correct order of mathematical operators in mathematics and computer programming,
A – Addition, Subtraction, Multiplication, Division
B – Division, Multiplication, Addition, Subtraction
C – Multiplication, Addition, Division, Subtraction
D – Mathematical operators can be done in any order
Q 6 – Which scanf() statement will you use to scan a float value (a) and double value (b)?
Float a;
Double b;
A – scanf(“%f %f”, &a, &b);
B – scanf(“%lf % lf “, &a, &b);
C – scanf(“%Lf %Lf”, &a, &b);
D – scanf(“%f %lf”, &a, &b);
Q 7 – Choose the function that is most appropriate for reading in a multi-word string?
A – strnset()
B – scanf()
C – strchr()
D – gets()
Q 8 – What is the following program doing?
#include<stdio.h>
main()
{
FILE *stream=fopen(“a.txt”,’r’);
}
A – Trying to open “a.txt” in read mode
B – Trying to open “a.txt” in write mode.
C – “stream” is an invalid identifier
D – Compile error
Q 9 – What is the output of the following program?
#include<stdio.h>
main()
{
union abc {
int x;
char ch;
}var;
var.ch = ‘A’;
printf(“%d”, var.x);
}
A – A
B – Garbage value
C – 65
D – 97
Q 10 – A local variable is stored in ___
A – Code segment
B – Stack segment
C – Heap segment
D – None of the above
Answer with explaination
1)B
Explaination
Hi, control reaches default-case after comparing the rest of case constants.
2)A
Explaination
As the code of macro gets expanded at the line of call, therefore macro gets executed faster with no overhead of context switch.
3)D
Explaination
It is invalid to access the NULL address hence giving run time error.
4)B
Explaination
fclose(), it flushes the buffers associated with the stream and disconnects the stream with the file.
5)B
Explaination
It is BODMAS.
6)D
Explaination
In C Programming, the scanf() can be used to read a formatted string from the stdin stream, where as; scanf() uses %lf to read a double value and %f to read a floating-point number in fixed decimal format.
int scanf(const char *format, …)
7)D
Explaination
gets (); = Collects a string of characters terminated by a new line from the standard input stream stdin
8)D
Explaination
Compile error, second argument for fopen is invalid, should be a string.
9)C
Explaination
65, as the union variables share common memory for all its elements, x gets ‘A’ whose ASCII value is 65 and is printed.
10)B
Explaination
All the local variables are stored in a memory called as stack.