C programming mcq with answers - Practice Set 3

C Programming Practice Questions for Gate CSE exam, c programming questions,c programming questions and answers,c programming questions,c interview questions



 C  Programming Practice Question for GATE Exam


Hello Friends today in this post we will practice some c programming mcq. So practice these c programming mcq with answer.

 Loops and Cotrols



1. Consider the C program below.

#include
int *A, stkTop;
int stkFunc (int opcode, int val)
{
static int size=0, stkTop=0;
switch (opcode)
{
case -1:
size = val;
break;
case 0:
if (stkTop < size ) A[stkTop++]=val;
break;
default:
if (stkTop) return A[--stkTop];
}
return -1;
}
int main()
{
int B[20];
A=B;
stkTop = -1;
stkFunc (-1, 10);
stkFunc (0, 5);
stkFunc (0, 10);
printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));
}
The value printed by the above program is ___________
(a) 9 (b) 10
(c) 15 (d) 17

Solution: Option (c)

2. Which combination of the integer variables x, y and z makes the variable a get the value 4 in the following expression?

a = ( x > y ) ? (( x > z ) ? x : z) : (( y > z ) ? y : z )
(a) x = 3, y = 4, z = 2 (b) x = 6, y = 5, z = 3
(c) x = 6, y = 3, z = 5 (d) x = 5, y = 4, z = 5

Solution: Option (a)


3.

#include
int main()
{
int a = 5;
switch(a)
{
default:
a = 4;
case 6:
a--;
case 5:
a = a+1;
case 1:
a = a-1;
}
printf("%d \n", a);
return 0;
}
(a) 3 (b) 4
(c) 5 (d) None of these

Solution: Option (c)

4.

#include
int main()
{
int x = 3;
if (x == 2); x = 0;
if (x == 3) x++;
else x += 2;
printf("x = %d", x);
return 0;
}
(a) x = 4 (b) x = 2
(c) Compiler Error (d) x = 0

Solution: Option (b)

5.

#include
int main()
{
int i = 3;
while (i--)
{
int i = 100;
i--;
printf("%d ", i);
}
4
return 0;
}
(a) Infinite loop (b) 99 99 99
(c) 99 98 97 (d) 2 2 2

Solution: Option (b)


6. How many times kumar is printed?

#include
int main()
{
int i = -5;
while (i <= 5)
{
if (i >= 0)
break;
else
{
i++;
continue;
}
printf("kumar");
}
return 0;
}
(a) 10 times (b) 5 times
(c) Infinite times (d) 0 times

Solution: Option (d)



7. Predict the output of the following program:

#include
int main()
{
int check = 20, arr[] = {10, 20, 30};
switch (check)
{
case arr[0]: printf("Gates ");
case arr[1]: printf("Quiz ");
case arr[2]: printf("GatesQuiz");
}
return 0;
}

Solution: Option (d)



8. What is the output of the following program?

#include
int main()
{
char check = 'a';
switch (check)
{
case 'a' || 1: printf("Gates ");
case 'b' || 2: printf("Quiz ");
break;
default: printf("GatesQuiz");
}
return 0;
}
(a) Gates (b) Gates Quiz
(c) Gates Quiz GatesQuiz (d) Compile-time error

Solution: Option (d)

9. In the following program, X represents the Data Type of the variable check.

#include
int main()
{
X check;
switch (check)
{
// Some case labels
}
return 0;
}
Which of the following cannot represent X?
(a) int (b) char
(c) enum (d) float

Solution: Option (d)


10. Predict the output of the below program:

#include
int main()
{
int i = 3;
switch(i)
{
printf("Outside ");
7
case 1: printf("Gates");
break;
case 2: printf("Quiz");
break;
defau1t: printf("GatesQuiz");
}
return 0;
}
(a) Outside GatesQuiz
(b) GatesQuiz
(c) Nothing gets printed

Solution: Option (c)


11. What will be the output of the following C program segment? (GATE CS 2012)

char inchar = 'A';
switch (inchar)
{
case 'A' :
printf ("choice A \n") ;
case 'B' :
printf ("choice B ") ;
case 'C' :
case 'D' :
case 'E' :
default:
printf ("No Choice") ;
}
(a) No choice
(b) Choice A

(c) Choice A
Choice B No choice
(d) Program gives no output as it is erroneous

Solution: Option (c)



12.

#include
int main()
{
int i;
for (i = 1; i != 10; i += 2)
printf(" GatesQuiz ");
return 0;
}
(a) GatesQuiz GatesQuiz GatesQuiz GatesQuiz GatesQuiz
(b) GatesQuiz GatesQuiz GatesQuiz …. infinite times
(c) GatesQuiz GatesQuiz GatesQuiz GatesQuiz
(d) GatesQuiz GatesQuiz GatesQuiz GatesQuiz GatesQuiz GatesQuiz

Solution: Option (b)


gate question on c programming pdf



                           


13. Output of following C program?
#include
int main()
{

int i = 0;
for (printf("1st\n"); i < 2 && printf("2nd\n"); ++i && printf("3rd\n"))
{
printf("*\n");
}
return 0;
}
(a) 1st (b) 1st
2nd 2nd
* *
3rd 3rd
2nd 2nd
* *
3rd
(c) 1st (d) 1st
2nd 2nd
3rd 3rd
* *
2nd 1st
3rd 2nd
3rd

Solution: Option (b)

14.
# include
int main()
10
{
int i = 0;
for (i=0; i<20 i="" p="">{
switch(i)
{
case 0:
i += 5;
case 1:
i += 2;
case 5:
i += 5;
default:
i += 4;
break;
}
printf("%d ", i);
}
return 0;
}
(a) 5 10 15 20 (b) 7 12 17 22
(c) 16 21 (d) Compiler Error

Solution: Option (c)


15. Output?


<20 i="" p="">#include
int main()
{
int c = 5, no = 10;
do {
no /= c;
} while(c--);
printf ("%d\n", no);
return 0;
}
(a) 1 (b) Runtime Error
(c) 0 (d) Compiler Error


<20 i="" p="">Solution: Option (b)


16.

#include
int main()
{
int n;
for (n = 9; n!=0; n--)
printf("n = %d", n--);
return 0;
}

What is the output?
(a) 9 7 5 3 1 (b) 9 8 7 6 5 4 3 2 1
(c) Infinite Loop (d) 9 7 5 3


<20 i="" p="">Solution: Option (c)

17.
#include
int i;
int main()
{
if (i);
else
printf("√člse");
return 0;
}
What is correct about the above program?
(a) if block is executed.
(b) else block is executed.
(c) It is unpredictable as i is not initialized.
(d) Error: misplaced else

Solution: Option (b)

18.

#include
int main()
{
int i;
if (printf("0"))
i = 3;
else
i = 5;
printf("%d", i);
return 0;
}
Predict the output of above program?
(a) 3 (b) 5
(c) 03 (d) 05

Solution: Option (c)


19. Predict the output of the below program:
#include
#define EVEN 0
#define ODD 1
int main()
{
int i = 3;
switch (i & 1)
{
case EVEN: printf("Even");
break;
case ODD: printf("Odd");
break;

default: printf("Default");
}
return 0;
}
(a) Even (b) Odd
(c) Default (d) Compile-time error

Solution: Option (b)


20.

#include
int main()
{
int i = 3;
switch (i)
{
case 0+1: printf("Gates");
break;
case 1+2: printf("Quiz");
break;
default: printf("GatesQuiz");
}
return 0;
}
What is the output of the above program?
(a) Gates (b) Quiz
(c) GatesQuiz (d) Compile-time error

Solution: Option (b)

<20 i="" p="">
<20 i="" p="">Keywords: mcq in c programming, multiple choice questions in c, objective questions and answers in c programming,  <20 i="" p="">

COMMENTS

Name

addressing modes types,1,advance-java,2,advancejava,1,aktu entrance exam,1,aktu exam schedule,1,ASP,1,bare machine,1,base register and limit register,1,Basic Computer network questions,1,C Programming,15,C Plus Plus,1,C Programming,2,C Programming MCQ,2,C Programming Questions,2,C programming study material for gate exam,13,Cache Memory,1,CBNST Program,1,Childcare,1,CJ,2,Cloud Computing,1,COA GATE Questions,1,components of use case diagram,1,Computer Architecture,2,Computer architecture based questions for gate exam,11,Computer Network,3,Computer Network Study Material,4,Computer network study material for gate,2,Computer Networks,7,Computer Science Study Material for Gate,20,computer science study material for gate exam,36,content based image retrieval content based image retrieval system,1,contiguous memory allocation,2,Core Java,8,COre Java Interview Questions,1,core java interviews questions,1,cyber crime report,1,Cyber crime status,1,cybercrime and security,1,cybercrime examples,1,Data link Layer Questions,1,Data Mining,1,Data Structure Questions,1,Data Transmission Architecture,1,Data Transmission in wsn,1,DBMS,4,dbms question paper,1,DE,1,Digital Electronics,1,DS,1,dynamic linking,1,dynamic linking in memory management,1,Electroencephalogram,1,File Handling,1,file management in operating system notes,1,FOC,1,Fundamenatl of Computer,1,Gate 2017,5,Gate 2017 Admit card,1,Gate 2017 Exam Schedule,1,Gate 2017 Syllabus,1,gate 2018,1,gate cse study material,1,gate practice set,10,gate study material for computer science,18,Gate study material for computer science 2017,1,GatePreviousYear,1,General,3,HCL Aptitude Test,1,HR Interview Questions,1,HTML,1,Image Processing,1,Important Date of Gate 2017 Exam,1,Information Security Policy,1,internal and external fragmentation,1,JS,1,lagrange's interpolation formula,1,lagrange's interpolation formula examples,1,Looping in C,1,MComputing,1,memory fragmentation,1,memory management,1,memory management questions and answer in os,1,Motivational,4,NCER,2,Numerical Techniques Lab,1,OOT,1,Operating System,12,Operating System Gate Questions,1,Operating System Objective Questions,4,Operating System Questions Bank,1,Operating system questions for gate,1,Operating System Study material,2,operating system study material for gate exam,16,Operating system tutorial,2,page swapping,1,paged memory allocation,1,paged memory allocation in operating system,1,paging technique of memory management .paging technique,1,paging technique of memory management program in c,1,Pointer in C,5,Process based question for gate,1,Quiz on non conventional energy resources,1,Regression testing,1,relocation in memory management,1,relocation registe,1,relocation register,1,resident monitor,1,resident monitor in operating system,1,routing table,1,segmentation in memory management,1,segmentation in memory management in operating system,1,Servlet,1,session tracking,1,session tracking in java,1,session tracking in servlet,1,Software Engineering,10,Software Engineering baes study material for gate,1,software engineering interview questions,1,Software Quality Assurance,3,software verification methods,1,SPM,1,Structure in C,1,Study Material for gate Computer Science,11,swapping in memory management,1,swapping in operating system,1,TCS Code Vita,1,TCS Interview Questions,1,Technical Interview,1,Technical Questions from DBMS,1,Thrashing in Operating System,1,Threads concept in operating system,1,Tips to Learn Coding,1,Top 30 Core Java Interview Questions with Answer,2,top down approach,1,top down approach in programming,1,Types of operating system,1,UML,1,use case diagram explanation,1,website uses cookies,1,what is cookies website,1,What is process control block ?,1,what is software testing?,1,Wireless Sensor Network,3,worst fit algorithm for memory allocation,1,XML,1,
ltr
item
Computer Science Junction: C programming mcq with answers - Practice Set 3
C programming mcq with answers - Practice Set 3
C Programming Practice Questions for Gate CSE exam, c programming questions,c programming questions and answers,c programming questions,c interview questions
https://3.bp.blogspot.com/-arGJ7nNuQGM/WwFrQWMkSWI/AAAAAAAAAvM/Z69h7-wrHk4A1JnmmIbZuLYxhWPW6RTUgCEwYBhgL/s1600/C%2BProgramming%2BQuestions.jpg
https://3.bp.blogspot.com/-arGJ7nNuQGM/WwFrQWMkSWI/AAAAAAAAAvM/Z69h7-wrHk4A1JnmmIbZuLYxhWPW6RTUgCEwYBhgL/s72-c/C%2BProgramming%2BQuestions.jpg
Computer Science Junction
https://www.computersciencejunction.in/2018/05/c-programming-mcq-with-answers.html
https://www.computersciencejunction.in/
https://www.computersciencejunction.in/
https://www.computersciencejunction.in/2018/05/c-programming-mcq-with-answers.html
true
425357657003182083
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share. STEP 2: Click the link you shared to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy