0% found this document useful (0 votes)
2K views

C MCQ

The document contains multiple choice questions related to C programming language. It asks about the father of C language, reserve keywords, data types, operators, functions, pointers and other concepts. Each question is followed by 4 answer options and the correct answer is highlighted.

Uploaded by

Karthiya Banu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

C MCQ

The document contains multiple choice questions related to C programming language. It asks about the father of C language, reserve keywords, data types, operators, functions, pointers and other concepts. Each question is followed by 4 answer options and the correct answer is highlighted.

Uploaded by

Karthiya Banu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 65

 Who is known as the father of C Language

?
A.James A. Sosling
 B.Vjarne Stroustrup

C.Dennis Ritchie
 D.Dr. E. F. Codd

 Answer : Option C
 C Language was developed in the year
____
A.1970
 B.1975

C.1980
 D.1985

 Answer : Option A
 Which one is not a reserve keyword in C
Language?
A.auto
 B.main

C.case
 D.register

 Answer : Option B
 Prototype of a function means _____
A.Name of Function
 B.Output of Function

C.Declaration of Function
 D.Input of a Function

 Answer : Option C
 Name the loop that executes at least once.
A.For
 B.If

C.do-while
 D.while

 Answer : Option C
 Far pointer can access _____
A.Single memory location
 B.No memory location

C.All memory location
 D.First and Last Memory Address

 Answer : Option C

A pointer pointing to a memory location of the
variable even after deletion of the variavle is
known as _____
A.far pointer
 B.dangling pointer

C.null pointer
 D.void pointer

 Answer : Option B
 An uninitialized pointer in C is called ___
A.Constructor
 B.dangling pointer

C.Wild Pointer
 D.Destructor

 Answer : Option C
 A pointer that is pointing to NOTHING is
called ____
A.VOID Pointer
 B.DANGLING Pointer

C.NULL Pointer
 D.WILD Pointer
 Dangling pointers arise during object
destruction, when an object that has an
incoming reference is deleted or deallocated,
without modifying the value of the pointer,
so that the pointer still points to the memory
location of the deallocated memory.
 A void pointer is nothing but
a pointer variable declared using the
reserved word inC 'void'. When
a pointer variable is declared using
keyword void – it becomes a general
purpose pointer variable. Address of any
variable of any data type (char, int, float
etc.)can be assigned to a void
pointer variable
 A pointer which is not initialized with any
address is called wild pointer. The wild pointer
is by default stored with the garbage value.
 A pointer of any type has such a reserved
value. Formally, each specific pointertype (
int * , char * etc.) has its own dedicated null-
pointer value. Conceptually, when
a pointer has that null value it is not pointing
anywhere. ... So, once again,null pointer is a
value, while void pointer is a type.
 Answer : Option C
 5. Variable names beginning with underscore
is not encouraged. Why?
a) It is not standardized
b) To avoid conflicts since assemblers and
loaders use such names
c) To avoid conflicts since library routines use
such names
d) To avoid conflicts with environment
variables of an operating system
 Answer:c
 2. C99 standard guarantess uniqueness of
_____ characters for external names.
a) 31
b) 6
c) 12
d) 14
 Answer:a
Explanation:ISO C99 compiler may consider
only first 31 characters for external
variables having 31 characters due to which it
may not be unique.
 Which is valid C expression?
a) int my_num = 100,000;
b) int my_num = 100000;
c) int my num = 1000;
d) int $my_num = 10000;
 Answer:b
Explanation:space, comma and $ cannot be
used in a variable name.
 What is the output of this C code?
 #include <stdio.h>
 int main()
 {
 printf("Hello World! %d \n", x);
 return 0;
 }
 a) Hello World! x;
b) Hello World! followed by a junk value
c) Compile time error
d) Hello World!
 Answer:c
Explanation:It results in an error since x is used
without declaring the variable x.
Output:
$ cc pgm1.c
pgm1.c: In function ‘main’:
pgm1.c:4: error: ‘x’ undeclared (first use in this
function)
pgm1.c:4: error: (Each undeclared identifier is
reported only once
pgm1.c:4: error: for each function it appears in.)
 What is the output of this C code?
 #include <stdio.h>
 int main()
 {
 int y = 10000;
 int y = 34;
 printf("Hello World! %d\n", y);
 return 0;
 }
 a) Compile time error
b) Hello World! 34
c) Hello World! 1000
d) Hello World! followed by a junk value
 Answer:a
Explanation:Since y is already defined,
redefining it results in an error.
Output:
$ cc pgm2.c
pgm2.c: In function ‘main’:
pgm2.c:5: error: redefinition of ‘y’
pgm2.c:4: note: previous definition of ‘y’ was
here
 Which of the following is not a valid variable
name declaration?
a) float PI = 3.14;
b) double PI = 3.14;
c) int PI = 3.14;
d) #define PI 3.14
 Answer:d
Explanation:#define PI 3.14 is a macro
preprocessor, it is a textual substitution.
 What is the problem in following variable
declaration?
float 3Bedroom-Hall-Kitchen?;
a) The variable name begins with an integer
b) The special character ‘-‘
c) The special character ‘?’
d) All of the mentioned
 Answer:d
Explanation:A variable name cannot start
with an integer, along with that the C
compiler
interprets the ‘-‘ and ‘?’ as a minus operator
and a question mark operator respectively.
 Comment on the output of this C code?
 #include <stdio.h>
 int main()
 {
 int ThisIsVariableName = 12;
 int ThisIsVariablename = 14;
 printf("%d", ThisIsVariablename);
 return 0;
 }
 a) The program will print 12
b) The program will print 14
c) The program will have a runtime error
d) The program will cause a compile-time
error due to redeclaration
 Answer:b
Explanation:Variable names
ThisIsVariablename and ThisIsVariableName
are both distinct as C is case sensitive.
Output:
$ cc pgm4.c
$ a.out
14
 Which of the following cannot be a variable
name in C?
a) volatile
b) true
c) friend
d) export
 Answer: a
Explanation:volatile is C keyword.
 The format identifier ‘%i’ is also used for
_____ data type?
a) char
b) int
c) float
d) double
 Answer:b
Explanation:Both %d and %i can be used as a
format identifier for int data type.
 Which data type is most suitable for storing a
number 65000 in a 32-bit system?
a) signed short
b) unsigned short
c) long
d) int
 Answer:b
Explanation:65000 comes in the range of
short (16-bit) which occupies the least
memory. Signed short ranges from -32768 to
32767 and hence we should use unsigned
short.m
 Which of the following is a User-defined data
type?
a) typedef int Boolean;
b) typedef enum {Mon, Tue, Wed, Thu, Fri}
Workdays;
c) struct {char name[10], int age};
d) all of the mentioned
 Answer:d
Explanation:typedef and struct are used to
define user-defined data types.
 What is the output of this C code?
 #include <stdio.h>
 int main()
 {
 signed char chr;
 chr = 128;
 printf("%d\n", chr);
 return 0;
 }
 a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned
 Answer:b
Explanation:signed char will be a negative
number.
Output:
$ cc pgm2.c
$ a.out
-128
 Comment on the output of this C code?
 #include <stdio.h>
 int main()
 {
 char c;
 int i = 0;
 FILE *file;
 file = fopen("test.txt", "w+");
 fprintf(file, "%c", 'a');
 fprintf(file, "%c", -1);
 fprintf(file, "%c", 'b');
 fclose(file);
 file = fopen("test.txt", "r");
 while ((c = fgetc(file)) != -1)
 printf("%c", c);
 return 0;
 }
 a) a
b) Infinite loop
c) Depends on what fgetc returns
d) Depends on the compiler
 Answer:a
Explanation:None.
Output:
$ cc pgm3.c
$ a.out
a
 What is short int in C programming?
a) Basic datatype of C
b) Qualifier
c) short is the qualifier and int is the basic
datatype
d) All of the mentioned
 Answer:c
 Comment on the output of this C code?
 #include <stdio.h>
 int main()
 {
 float f1 = 0.1;
 if (f1 == 0.1)
 printf("equal\n");
 else
 printf("not equal\n");
 }
 a) equal
b) not equal
c) Output depends on compiler
d) None of the mentioned
 Answer:b
Explanation:0.1 by default is of type double
which has different representation than float
resulting in inequality even after conversion.
Output:
$ cc pgm4.c
$ a.out
not equal
 Which of the datatypes have size that is
variable?
a) int
b) struct
c) float
d) double
 Answer:b
Explanation:Since the size of the structure
depends on its fields, it has a variable size.
 Comment on the following?
const int *ptr;
a) You cannot change the value pointed by ptr
b) You cannot change the pointer ptr itself
c) Both (a) and (b)
d) You can change the pointer as well as the
value pointed by it
 Answer:a

You might also like