QUIZ- 5 OF C PROGRAMMING LANGUAGE
QUIZ- 5 OF C PROGRAMMING LANGUAGE
Q 1 – What is the output of the following program?
#include<stdio.h>
main()
{
int x = 1;
do
printf(“%d “, x);
while(x++<=1);
}
A – 1
B – 1 2
C – No output
D – Compile error
Q 2 – What is the output of the following program?
#include<stdio.h>
main()
{
int a[] = {2,1};
printf(“%d”, *a);
}
A – 0
B – 1
C – 2
D – Compile error.
Q 3 – Which of the following is used in mode string to open the file in binary mode?
A – a
B – b
C – B
D – bin
Q 4 – What is the output of the following program?
#include<stdio.h>
void main()
{
char s[] = “C++”;
printf(“%s “,s);
s++;
printf(“%s”,s);
}
A – C++ C++
B – C++ ++
C – ++ ++
D – Compile error
Q 5 – The given below program allocates the memory, what function will you use to free the allocated memory?
#include<stdio.h>
#include<stdlib.h>
#define MAXROW 4
# define MAXCOL 5
int main ()
{
int **p, i, j
p = (int **) malloc(MAXROW * sizeof(int*));
return 0;
}
A – memfree(int p);
B – free(p);
C – dealloc(p);
D – Both, free(p); & dealloc(p);
Q 6 – In the given below code, the P2 is
Typedef int *ptr;
ptr p1, p2;
A – Integer
B – Integer pointer
C – Both, Integer & Integer pointer
D – None of above
Q 7 – Which statement can print \n on the screen?
A – printf(“\\n”);
B – printf(“n\”);
C – printf(“n”);
D – printf(‘\n’);
Q 8 – What is the output of the following code snippet?
#include<stdio.h> main(){ int *p = 15; printf(“%d”,*p);}
A – 15
B – Garbage value
C – Runtime error
D – Compiler error
Q 9 – Identify the incorrect file opening mode from the following.
A – r
B – w
C – x
D – a
Q 10 – What is the output of the below code snippet.
#include<stdio.h>
main()
{
printf(“%d”, -11%2);
}
A – 1
B – -1
C – 5.5
D – -5.5
QUIZ- 5 OF C PROGRAMMING LANGUAGE
Answer with explaination
1)B
Explanation
1 2, do..while is an entry control loop. As the expression x++ is post form loop continues for 2nd time also.
2)C
Explanation
2, as ‘a’ refers to base address.
3)B
Explanation
To perform unformatted data I/O a file is opened in binary mode and is represented with the alphabet ‘b’ in the mode string.
4)D
Explanation
‘s’ refers to a constant address and cannot be incremented.
5)B
Explanation
free() is the function in C language to release the allocated memory by any dynamic memory allocating built in library function.
#include<stdio.h>#include<stdlib.h> #define MAXROW 4# define MAXCOL 5 int main (){ int **p, i, j p = (int **) malloc(MAXROW * sizeof(int*)); return 0;}
6)B
Explanation
Ptr is an alias to int*.
7)A
Explanation
Option A is the correct answer. In C programming language, “\n” is the escape sequence for printing a new line character. In printf(“\\n”); statement, “\\” symbol will be printed as “\” and “n” will be known as a common symbol.
8)C
Explanation
Runtime error, as the pointer variable is not holding proper address, writing/reading the data from the same raises runtime error.
9)C
Explanation
x, there is no such mode called “x”.
10)B
Explanation
Modulus (%) operator is meant to give reminder for integer division.
To get more quiz on “programming language c with explanation”please click here:
https://www.soluversity.in/quiz-6-c-programming-language
TO know more about c programming language visit there: