Sei sulla pagina 1di 20

CppBuzz.

com Search topic


Home C C++ Java Python Perl PHP SQL JavaScript Linux Online Test Forum

Home » C » 100 MCQ on C programming

100 MCQ on C Programming


Page 1 (1 - 50)

«12»

Question: 1

Is it possible to run
program without

(A) Yes
(B) No

Show Ans

Ans: B

Hint:
Ideally No but remember pragma directives allows few function to be executed before and after main() function

Compiler Forum
Beginner function[Posted by: Admin | Chicago, USA]

Question: 2

How many main()


function we can have

(A) 1
(B) 2
(C) No Limit
(D) Depends on Compiler

Show Ans

Ans: A

Hint:
We can't have more than one main() function in a project.

Compiler Forum
Beginner function[Posted by: Admin | Chicago, USA]

Question: 3

What is sizeof() in
C?

(A) Operator
(B) Function
(C) Macro
(D) None of these

Show Ans

Ans: A

Hint:
Anything which has opening and closing braces () is not function

Compiler Forum
Expert operators[Posted by: Admin | Chicago, USA]
Question: 4

Is it true that a
function may have

(A) True
(B) False

Show Ans

Ans: A

Hint:
Declaration like int sum(int, int); is allowed number of times but definition int sum(int a, int b) { return a+b; } is allowed only one time. Multiple
definition of same function is compilation error ( redefinition error )

Compiler Forum
Practitioner function[Posted by: Admin | Chicago, USA]

Question: 5

int main()
{
extern int i;
i = 20;
printf("%d",
sizeof(i));
return 0;
}

(A) 20
(B) 0
(C) Undefined reference to i
(D) Linking Error

Show Ans

Ans: C

Hint:
extern int i; tell the compiler that int i is declared in some other file, in this code we have not included any other header file so it will cause
compilation error.

Compiler Forum
Beginner storgeclass[Posted by: Admin | Chicago, USA]

Job Oriented ML Course


Ad 1:1 Mentorship. 150+ hrs of
Training. 15 Real World Case…
Applied AI Course

Learn more

Question: 6

Is the following
statement a
declaration or

(A) Declaration
(B) Definition

Show Ans

Ans: A

Compiler Forum
Beginner storgeclass[Posted by: Admin | Chicago, USA]

Question: 7
main()
{
int x = 10;
{
int x =
0;

printf("%d",x);
}
}

(A) 10
(B) Compilation Error
(C) 0
(D) Undefined

Show Ans

Ans: C

Hint:
It will print nearest values that is x =10

Compiler Forum
Beginner loops[Posted by: Admin | Chicago, USA]

Question: 8

int x = 10;

int main()
{
int x = 0;
printf("%d",x);
return 0;
}

(A) 10
(B) 0
(C) Compilation Error
(D) Undefined

Show Ans

Ans: B

Hint:
It will print nearest values that is x =0. To print x=10; scope resolution operator :: should be used like printf("%d", ::a)

Compiler Forum
Expert datatype[Posted by: Admin | Chicago, USA]

Question: 9

//This program is
compiled on 32 bit
DEV-C++
int main()
{

char *ptr1, *ptr2;


printf("%d %d",
sizeof(ptr1),
sizeof(ptr2));

(A) 1 1
(B) 2 2
(C) 4 4
(D) Undefined

Show Ans

Ans: C

Hint:
On 32 compilers pointer's size is 4 bytes while on 64 bit compiler pointers size is 8 bytes. Note - If your computer is 64 bits then you can use both
32 bits and 64 bits compiler on it.

Compiler Forum
Beginner pointers[Posted by: Admin | Chicago, USA]
Question: 10

Which programming
language is more

(A) Java
(B) PHP
(C) C
(D) Visual Basic

Show Ans

Ans: C

Hint:
Execution flow ( faster to slower) Binary -> Assembly -> C -> C++ > Java / PHP / VB

Compiler Forum
Beginner other[Posted by: Admin | Chicago, USA]

Question: 11

void main()
{
int a = printf
("CppBuzz.com");
printf("%d", a);
}

(A) Compilation Error


(B) 0
(C) CppBuzz.com
(D) CppBuzz.com11

Show Ans

Ans: D

Hint:
printf() prints and returns the number of characters it has printed that is why its output is CppBuzz.com11, 11 is returned by printf() function

Compiler Forum
Beginner function[Posted by: Admin | Chicago, USA]

Question: 12

What should be the


output:
void main()
{
int a = 10/3;
printf("%d",a);
}

(A) 3.33
(B) 3.0
(C) 3
(D) 0

Show Ans

Ans: C

Hint:
integer division ( int/ int ) is int only hence instead of printing 3.33 it will print 3 only. Float part is discarded in such cases.

Compiler Forum
Beginner datatype[Posted by: Admin | Chicago, USA]

Question: 13

Which of the
following is executed
(A) #include<stdio.h>
(B) return 0
(C) void main(int argc , char ** argv)
(D) None of above

Show Ans

Ans: A

Hint:
statements starting with # symbol are always processed by pre-processor

Compiler Forum
Beginner datatype[Posted by: Admin | Chicago, USA]

Question: 14

void main()
{
int a = 10.5;
printf("%d",a);

(A) 10.5
(B) 10
(C) 0
(D) Compilation Error

Show Ans

Ans: B

Hint:
compiler will convert float values to integer value after seeing %d so instead of printing 10.5 it will print it integer value i.e 10

Compiler Forum
Beginner datatype[Posted by: Admin | Chicago, USA]

Question: 15

int main()
{
int _ = 10;
int __ = 20;
int ___ = _ +
__;

printf("__%d",___);
return 0;
}

(A) Compilation Error


(B) Runtime Error
(C) __0
(D) __30

Show Ans

Ans: D

Hint:
multiple underscore ie. _ can be used to create varialbes.

Compiler Forum
Expert datatype[Posted by: Admin | Chicago, USA]

Best Free Android


Emulator
Ad Flexible control with mouse and
keyboard
Tencent Gaming Buddy

Download

Question: 16
int main()
{
int a = 5;
int b = 10;
int c = a+b;
printf("%i",c);
}

(A) 0
(B) 15
(C) Undefined i
(D) Any other Compiler Error

Show Ans

Ans: B

Hint:
%i is also used to printf numberic values in C. %d and %i both solve the same purpose.

Compiler Forum
EXpert datatype[Posted by: Admin | Chicago, USA]

Question: 17

int main()
{
char arr[5]="The
CppBuzz.com";
printf("%s",arr);
return 0;
}

(A) The CppBuzz.com


(B) The C
(C) The CppBuzz
(D) Compilation Error

Show Ans

Ans: D

Hint:
Size of arr is 5 but the code is trying to assign string which is more than 5

Compiler Forum
Practitioner datatype[Posted by: Admin | Chicago, USA]

Question: 18

int main()
{
int a = 320;
char *ptr;
ptr =( char *)&a;

printf("%d",*ptr);
return 0;
}

(A) 320
(B) 60
(C) 160
(D) 64

Show Ans

Ans: D

Hint:
To understand it you have to convert 320 to binary form which is 101000000, (9 digits) Now code is typecasting this value to char*, which takes 8
bits; so from the 9 digits ptr will stor only 8 values (01000000) which comes 64.

Compiler Forum
Practitioner pointers[Posted by: Admin | Chicago, USA]

Question: 19
int main()
{
int x;
x=10,20,30;
printf("%d",x);
return 0;
}

(A) 10
(B) 20
(C) 30
(D) Compilation Error

Show Ans

Ans: A

Hint:
When there are multiple , then assignment takes place from right to left hence 10 is the last value which is assign to x variable.

Compiler Forum
Expert operators[Posted by: Admin | Chicago, USA]

Question: 20

How many times


CppBuzz.com is
printed?
void main()
{
int a = 0;
while(a++ < 5-++a)
printf("CppBuzz.com")

(A) 5 times
(B) 4 times
(C) 2 times
(D) 1 time

Show Ans

Ans: D

Compiler Forum
Expert loops[Posted by: Admin | Chicago, USA]

Question: 21

How many times


CppBuzz.com is
printed?

void main()
{
int a = 0;
while(a++ < 5)
printf("CppBuzz.com")

(A) 4 times
(B) 5 times
(C) 0 time
(D) Infinite times

Show Ans

Ans: B

Hint:
Here while loop is execuated for a = 0 to a = 4 which is 5 times execuation hence CppBuzz.com is printed 5 times.

Compiler Forum
Practitioner loops[Posted by: Admin | Chicago, USA]

Question: 22
How many times
CppBuzz.com is
printed?
void main()
{
int a = 0;
while(a++)
printf("CppBuzz.com")

(A) 1 time
(B) 0 time
(C) Infinite times(Untill Stack is overflow)
(D) 2 times

Show Ans

Ans: B

Hint:
Here while loop is evaluated as while(0) which means it will be executed 0 times and since printf is also part of it so nothing would be printed.
Note:- if there are no { } braces after any loop then only the next statement is considered as a part of the loop.

Compiler Forum
Beginner loops[Posted by: Admin | Chicago, USA]

Question: 23

How many times


CppBuzz.com is
printed?
void main()
{
int a = 0;
while(a)
printf("CppBuzz.com")

(A) 1 time
(B) Compilation Error
(C) 0 time
(D) Infinite Times(Untill Stack is Overflow)

Show Ans

Ans: C

Hint:
while loop is evaluated as while(0) which means while loop will be executed 0 times and since printf() is also part of it so nothing is printed here.

Compiler Forum
Beginner loops[Posted by: Admin | Chicago, USA]

Question: 24

How many times


CppBuzz.com is
printed?
void main()
{
int a = 0;
while(++a)
{

printf("CppBuzz.com")

(A) 1 time
(B) Infinite Times(Untill Stack is overflow)
(C) 2 times
(D) Error

Show Ans

Ans: B

Hint:
Here while loop is evaluated as while(1) which means it will run infinite times.

Compiler Forum
Beginner loops[Posted by: Admin | Chicago, USA]
Question: 25

How may times


CppBuzz.com is
printed?
void main()
{
int a = 0;
while(++a++);
{

printf("CppBuzz.com")

(A) 1 time
(B) 0 time
(C) Infinite times
(D) Error: Lvalue Required

Show Ans

Ans: D

Hint:
We can't use preincrement and postincrement operator same time on same variable.

Compiler Forum
Beginner loops[Posted by: Admin | Chicago, USA]

Best Free Android


Emulator
Ad Flexible control with mouse and
keyboard
Tencent Gaming Buddy

Download

Question: 26

How many times


CppBuzz.com is
printed?
void main()
{
int a = 0;
while(a++);
{

printf("CppBuzz.com")

(A) 0 time
(B) 1 time
(C) Compilation Error
(D) Infinite times

Show Ans

Ans: B

Hint:
Here while loop is evaluated as while(0) because it has post increment operator. And since while(0) is terminated by ; so printf() will not be part of it
and hence it is printed 1 time.

Compiler Forum
Practitioner loops[Posted by: Admin | Chicago, USA]

Question: 27

How many times


CppBuzz.com is
printed on console?
void main()
{
int a = 0;
while(a++)
{

printf("CppBuzz.com")
(A) Nothing is printed on screen
(B) 0 time
(C) 1 time
(D) Infinite times (Untill Stack overflow)

Show Ans

Ans: A

Hint:
Here while loop is evaluated as while(0) because it has a post increment operator and a is incremented later after while loop. While(0) means loop
will not run.

Compiler Forum
Practitioner loops[Posted by: Admin | Chicago, USA]

Question: 28

How many times


CppBuzz.com is
printed on console?
void main()
{
int a = 0;
while(a==0)
{

printf("CppBuzz.com")

(A) 0 times
(B) Infinite times (Untill Stack is overflow)
(C) 1 time
(D) Nothing is printed

Show Ans

Ans: B

Hint:
while(0==0) is evaluated as while(1) which means while loop is execuated infinite times

Compiler Forum
Expert loops[Posted by: Admin | Chicago, USA]

Question: 29

What is printed on
console?
void main()
{
int a = 0;
while(a)
{

printf("CppBuzz.com")
;

(A) CppBuzz.com is printed Infinite times


(B) CppBuzz.com is printed 1 time only
(C) Nothing is printed
(D) Program gives error

Show Ans

Ans: C

Hint:
Here while loop is evaluated as while(0) which means while loop will not be executed.

Compiler Forum
Practitioner loops[Posted by: Admin | Chicago, USA]

Question: 30
How many times
CppBuzz.com is
printed?
void main()
{
while(1);
{

printf("CppBuzz.com")

(A) 1 time
(B) 0 time
(C) Compilation/Runtime Error
(D) Blank Screen in Infinite Loop

Show Ans

Ans: D

Hint:
While(1) is always infinite loop in C programming. So while will run but since it is terminated by ; and printf() is not part of it.

Compiler Forum
Practitioner loops[Posted by: Admin | Chicago, USA]

Question: 31

How many times


CppBuzz.com is
printed?

void main()
{
while(1)
{

printf("CppBuzz.com")

(A) 1 time
(B) Compilation Error
(C) Infinite times
(D) Runtime Error

Show Ans

Ans: C

Hint:
while(1) means while will run for forever it also means while(true)

Compiler Forum
Practitioner loops[Posted by: Admin | Chicago, USA]

Question: 32

What is output of
below program?

void main()
{
int i,j,count;
count=0;
for(i=0; i<5; i++);
{

for(j=0;j<5;j++);
{
count++;
}
}
printf("%d",count);

(A) 55
(B) 54
(C) 1
(D) 0

Show Ans
Ans: C

Hint:
if we put ; after for() then for loop doesn't run anything which is inside {}

Compiler Forum
Practitioner loops[Posted by: Admin | Chicago, USA]

Question: 33

What is output of
below program?

void main()
{
int i;
for(i=0; i<5; i++);
{

printf("cppbuzz");
}

(A) cppbuzz is printed 5 times


(B) Compilation Error
(C) cppbuzz is printed 1 times
(D) Nothing is printed

Show Ans

Ans: C

Hint:
You might be thinking that it should print 5 times but it is printing 1 time only because for loop is terminated by ; which means for loop will run 5
times but printf() is not part of that loop.

Compiler Forum
Practitioner loops[Posted by: Admin | Chicago, USA]

Question: 34

What is output of
below program?

void main()
{
int i,j,k,count;
count=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
count++;
}
}
printf("%d",count);
}

(A) 5
(B) 10
(C) 25
(D) 50

Show Ans

Ans: C

Hint:
This code has 25 iterations of for loops that is why count++ is executed 25 times hence its value becomes 25.

Compiler Forum
Practitioner loops[Posted by: Admin | Chicago, USA]

Question: 35
What is output of
below program?
void main()
{
int i,j;
for(i =
0,j=0;i<5;i++)
{
printf("%d%d--
",i,j);

(A) 0--01--12--23--34--
(B) 00--10--20--30--40--
(C) Compilation Error
(D) 00--01--02--03--04--

Show Ans

Ans: B

Hint:
In this code only i is incrementing starting from 0 to 4 but j is 0 only.

Compiler Forum
Expert loops[Posted by: Admin | Chicago, USA]

Question: 36

What is output of
below program?

void main()
{
int i;
for(i=0; i<5; ++i++)
{
printf("Hello");
}
}

(A) Hello is printed 5 times


(B) Compilation Error
(C) Hello is printed 2 times
(D) Hello is printed 3 times

Show Ans

Ans: B

Hint:
C doesn't allow using preincrement & postincrement on a variable on same time like ++i++

Compiler Forum
Expert loops[Posted by: Admin | Chicago, USA]

Question: 37

What is the output of


below program?
void main()
{
int i;

for(i = 0,i<5,i++)
{
printf("Hello");
}
}

(A) Hello is printed 5 times


(B) Compilation Error
(C) Runtime Error
(D) Hello is printed 4 times

Show Ans

Ans: B

Hint:
for loop should have semicolumn ; not comma , in its syntax. Using , instead of ; produces compilation error.

Compiler Forum
Expert loops[Posted by: Admin | Chicago, USA]

Question: 38

What is output of
below program?

void main()
{
for(; ;);
for(; ;);
printf("Hello");

(A) Compilation Error


(B) Runtime Error
(C) Nothing is printed
(D) Hello is printed infinite times

Show Ans

Ans: C

Hint:
blank for loop with ; ; is always infinite loop. printf() will never executed in this program.

Compiler Forum
Expert loops[Posted by: Admin | Chicago, USA]

Question: 39

What is the output of


below program?

void main()
{
for(; ;)
for(; ;)

printf("Hello..");
}

(A) Compilation Error


(B) Runtime Error
(C) Hello is printed one time
(D) Hello is printed infinite times

Show Ans

Ans: D

Hint:
Always remember, a for loop with only two ; is infinite loop. And it is because there is no initialization, condition & increment/decrements

Compiler Forum
Expert loops[Posted by: Admin | Chicago, USA]

Question: 40

How many loops are


there in C

(A) 2
(B) 3
(C) 4
(D) 1
Show Ans

Ans: B

Hint:
C Language has only three loops - for, while, do while

Compiler Forum
Beginner loops[Posted by: Admin | Chicago, USA]

Proudly Launching Subscription Model in


Become Local Solar Dealer Solar Business, Enquire Today, Get Extra
IndiaGoSolar Bene t

Question: 41

When C Language was


invented?

(A) 1970
(B) 1972
(C) 1978
(D) 1979

Show Ans

Ans: B

Hint:
Dennis MacAlistair Ritchie was an American computer scientist. He created the C programming language and, with long-time colleague Ken
Thompson.

Compiler Forum
Beginner other[Posted by: Admin | Chicago, USA]

Question: 42

What is the meaning


of below lines?
void sum (int, int);

(A) sum is function which takes int arguments


(B) sum is a function which takes two int arguments and returns void
(C) it will produce compilation error
(D) Can't comment

Show Ans

Ans: B

Hint:
Solve more questions on functions here - https://www.cppbuzz.com/interview-questions-on-function-in-c

Compiler Forum
Practitioner function[Posted by: Admin | Chicago, USA]

Question: 43

The concept of two


functions with same

(A) Operator Overloading


(B) Function Overloading
(C) Function Overriding
(D) Function renaming

Show Ans

Ans: B

Hint:
C Language supports the feature of having two functions with same name but number & type of arguments must be different.

Compiler Forum
Practitioner function[Posted by: Admin | Chicago, USA]
Question: 44

What is output of
below code?

void main()
{
char name[]="Cppbuz";
int len;
int size;
len = strlen(name);
size = size_of(name);
printf("%d,%d",len,si
ze);

(A) 6,6
(B) 6,7
(C) 7,7
(D) 0,0

Show Ans

Ans: B

Hint:
This is very important difference in size_of() and strlen() functions. strlen() returns no of chracters in any string. While size_of() operator returns the
size which is actually including '\0' (null) character, null character is inserted at the end of all strings in C programming.

Compiler Forum
Practitioner function[Posted by: Admin | Chicago, USA]

Question: 45

What is the following


is invalid header
file in C?

(A) math.h
(B) mathio.h
(C) string.h
(D) ctype.h

Show Ans

Ans: B

Hint:
mathio.h is not a predefined header file. However we can create our own header files with any name.

Compiler Forum
Practitioner function[Posted by: Admin | Chicago, USA]

Best Work Integrated


MBA
Ad Regular program integrated with
experiential learning
www.voussm.edu.in

Learn more

Question: 46

Libray function
getch() belongs to

(A) stdio.h
(B) conio.h
(C) stdlib.h
(D) stdlibio.h

Show Ans

Ans: B

Hint:
Function getch() belongs to conio.h header file. This function is only supported by old compilers like Trubo C. Latest Compiler like GCC, Visual
Studio doesn't support it. Instead of getch() we can use getchar() to hold the screen.
Compiler Forum
Beginner function[Posted by: Admin | Chicago, USA]

Question: 47

Library function
pow() belongs to

(A) mathio.h
(B) math.h
(C) square.h
(D) stdio.h

Show Ans

Ans: B

Hint:
Mathematics related functions like pow(), sqrt() belongs to math.h header file.

Compiler Forum
Practitioner function[Posted by: Admin | Chicago, USA]

Question: 48

What is output of
below program?
void main()
{
const int a = 10;
printf("%d",++a);
}

(A) 11
(B) 10
(C) Compilation Error
(D) 0

Show Ans

Ans: C

Hint:
We can't modify the value of const variables. Result is compilation error.

Compiler Forum
Beginner operators[Posted by: Admin | Chicago, USA]

Question: 49

What is storage class


for variable A in
below code?

void main()
{
int A;
A = 10;
printf("%d", A);

(A) extern
(B) auto
(C) register
(D) static

Show Ans

Ans: B

Hint:
There are 4 types of storage classes in C and those are auto, register, extern and static. Every storage class has its own use. Whenever a local
variable is declared it is counted in auto storage class. Every storage class variables have some default value. In case of auto its default values is
garbage.

Compiler Forum
Expert storgeclass[Posted by: Admin | Chicago, USA]
Question: 50

Can we declare
function inside

(A) Yes
(B) No
(C) Depends on Compiler
(D) Yes but run time error

Show Ans

Ans: B

Hint:
C doesn't support but C++

Compiler Forum
Expert structure[Posted by: Admin | Chicago, USA]

«12»
Compile C code here | Upload C Questions

Browse C Categories
Preprocessor Assembler Compilation Datatypes Arrays Variables Pointers Functions Loops Switch Structures Union Enum Goto & Labels Storage Classes
Malloc & free Macros Conditional Operators File Handling gcc Others

Switch to C++ Questions

CppBuzz Forum☆

Now you can ask programming questions on our forum [continue..]

Shortcut links - MCQs

C
C++
Java
PHP
Python
Perl
SQL
JavaScript
Linux

Subjective Questions

142+ C++ F2F Interview Questions

Solved Problems

C Solved Problems
C++ Solved Problems

Free Projects

C Projects
C++ Projects

Online Compiler

C Compiler
C++ Compiler
PHP Compiler

Upload Questions

C
C++
Java
Python
Perl
PHP
SQL
Linux
JavaScript

Online Test

C
C++
Java
JavaScript
PHP

Get updates on latest questions by CppBuzz.com to your email box

GET IT FREE !
Enter your name*
Email*

I'm not a robot


reCAPTCHA
Privacy - Terms

SUBSCRIBE

About Us | Contact Us | Privacy Policy


Facebook | Instagram | Twitter
Copyright©CppBuzz.com

Potrebbero piacerti anche