C Programming MCQ

C programming Multiple-Choice Questions

If Else Statement In C: MCQs On If Else in C Language

If Else Statement In C. Multiple Choice Questions on If – Else – Then Statements

 

If Else Statement In C

 

Which of the following is an invalid if-else statement ?

a) if (if (a == 1)){}
b) if (func1 (a)){}
c) if (a){}
d) if ((char) a){}

View Answer

a) if (if (a == 1)){}

 

What will be the output of the following C code ?

#include <stdio.h>
int main()
{
if (printf(“%d”, printf(“)))
printf(“We are Happy”);
else if (printf(“1”))
printf(“We are Sad”);
}

a) 0We are Happy
b) 1We are Happy
c) 1We are Sad
d) compile time error

View Answer

d) compile time error

 

What will be the output ?

#include <stdio.h>
void main()
{
int x = 5;
if (x < 1)
printf(“hello”);
if (x == 5)
printf(“hi”);
else
printf(“no”);
}

a) hi
b) hello
c) no
d) error

View Answer

a) hi

 

What will be the output of the following c code ?

#include <stdio.h>
int main()
{
int a = 1;
if (a)
printf(“All is Well “);
printf(“I am Well\n”);
else
printf(“I am not a River\n”);
}

a) Output will be All is Well I am Well
b) Output will be I am Well I am not a River
c) Output will be I am Well
d) Compile time errors during compilation

View Answer

d) Compile time errors during compilation

 

If Else Statement In C

 

What will be the output of the following program ?

#include <stdio.h>
int x;
void main()
{
if (x)
printf(“hi”);
else
printf(“how are u”);
}

a) hi
b) how are you
c) compile time error
d) error

View Answer

b) how are you

 

What will be the output of the following code ?

#include <stdio.h>
int main()
{
int a = 1;
if (a–)
printf(“True”);
if (a++)
printf(“False”);
}

a) True
b) False
c) True False
d) No Output

View Answer
a) True

 

What will be the output of the program ?

#include <stdio.h>
void main()
{
int x = 5;
if (true);
printf(“hello”);
}

a) It will display hello
b) It will throw an error
c) Nothing will be displayed
d) Compiler dependent

View Answer

b) It will throw an error

 

The C statement “”if (a == 1 || b == 2) {}”” can be re-written as ?

a) if (a == 1)
if (b == 2){}

b) if (a == 1){}
if (b == 2){}

c) if (a == 1){}
else if (b == 2){}

d) none of the mentioned

View Answer

d) none of the mentioned

 

If Else Statement In C

 

What will be the output ?

#include <stdio.h>
void main()
{
int x = 0;
if (x == 0)
printf(“hi”);
else
printf(“how are u”);
printf(“hello”);
}

a) hi
b) how are you
c) hello
d) hihello

View Answer

d) hihello

 

What will be the output of the following c code ?

#include <stdio.h>
int main()
{
int x = 0;
if (x == 1)
if (x >= 0)
printf(“true\n”);
else
printf(“false\n”);
}

a) true
b) false
c) Depends on the compiler
d) No print statement

View Answer

d) No print statement

 

What will be the output of the following program ?

#include <stdio.h>
void main()
{
int x = 5;
if (x < 1);
printf(“Hello”);
}

a) Nothing
b) Run time error
c) Hello
d) Varies

View Answer

c) Hello

 

What will be the output of the following code ?

#include <stdio.h>
int main()
{
int x = 0;
if (x == 0)
printf(“true, “);
else if (x = 10)
printf(“false, “);
printf(“%d\n”, x);
}

a) false, 0
b) true, 0
c) true, 10
d) compile time error

View Answer

b) true, 0

 

If Else Statement In C

 

What will be the output of the program ?

INPUT = 1

#include <stdio.h>
void main()
{
double ch;
printf(“enter a value between 1 to 2:”);
scanf(“%lf”, &ch);
switch (ch)
{
case 1:
printf(“1”);
break;
case 2:
printf(“2”);
break;
}
}

a) Compile time error
b) 1
c) 2
d) Varies

View Answer

a) Compile time error

 

What will be the output ?

#include <stdio.h>
int main()
{
int x = 0;
if (x == 1)
if (x == 0)
printf(“inside if\n”);
else
printf(“inside else if\n”);
else
printf(“inside else\n”);
}

a) inside if
b) inside else if
c) inside else
d) compile time error

View Answer

c) inside else

 

What will be the output of the following c code ?

INPUT = 1

#include <stdio.h>
void main()
{
char *ch;
printf(“enter a value between 1 to 3:”);
scanf(“%s”, ch);
switch (ch)
{
case “1”:
printf(“1”);
break;
case “2”:
printf(“2”);
break;
}
}

a) 1
b) 2
c) Compile time error
d) No Compile time error

View Answer

c) Compile time error

 

What will be the output of the following program ?

#include <stdio.h>
int main()
{
int x = 0;
if (x++)
printf(“true\n”);
else if (x == 1)
printf(“false\n”);
}

a) true
b) false
c) compile time error
d) undefined behaviour

View Answer

b) false

 

If Else Statement In C

 

What will be the output of the following c code ?

INPUT = 1

#include <stdio.h>
void main()
{
int ch;
printf(“enter a value between 1 to 2:”);
scanf(“%d”, &ch);
switch (ch)
{
case 1:
printf(“1\n”);
default:
printf(“2\n”);
}
}

a) 1
b) 2
c) 1 2
d) Run time error

View Answer

c) 1 2

 

What will be the output of the following C code ?

INPUT = 2

#include <stdio.h>
void main()
{
int ch;
printf(“enter a value between 1 to 2:”);
scanf(“%d”, &ch);
switch (ch)
{
case 1:
printf(“1\n”);
break;
printf(“Hi”);
default:
printf(“2\n”);
}
}

a) 1
b) Hi 2
c) Run time error
d) 2

View Answer

d) 2

 

What will be the output of the following C code ?

#include <stdio.h>
int main()
{
int x = 1;
if (x > 0)
printf(“inside if\n”);
else if (x > 0)
printf(“inside elseif\n”);
}

a) inside if

b) inside elseif

c) inside if
inside elseif

d) compile time error

View Answer

a) inside if

 

What will be the output of the following C code ?

INPUT = 1

#include <stdio.h>
void main()
{
int ch;
printf(“enter a value between 1 to 2:”);
scanf(“%d”, &ch);
switch (ch, ch + 1)
{
case 1:
printf(“1\n”);
break;
case 2:
printf(“2”);
break;
}
}

a) 1
b) 2
c) 3
d) Run time error

View Answer

b) 2

 

Arithmetic Operators In C MCQs: Arithmetic Operators MCQs

Arithmetic Operators In C MCQs. Multiple Choice Questions on the topic of Arithmetic Operators In C Programming Language.

 

Arithmetic Operators In C MCQs

 

What will be the output of the following C code ??

#include <stdio.h>
int main()
{
int a = 10, b = 5, c = 5;
int d;
d = a == (b + c);
printf(“%d”, d);
}

a) Syntax error
b) 1
c) 10
d) 5

View Answer

b) 1

 

What will be the output of the following C code ??

#include <stdio.h>
void main()
{
int y = 3;
int x = 5 % 2 * 3 / 2;
printf(“Value of x is %d”, x);
}

a) Value of x is 1
b) Value of x is 2
c) Value of x is 3
d) Compile time error

View Answer

a) Value of x is 1

 

What will be the output of the following C code ??

#include <stdio.h>
int main()
{
int a = 10;
double b = 5.6;
int c;
c = a + b;
printf(“%d”, c);
}

a) 15
b) 16
c) 15.6
d) 10

View Answer

a) 15

 

What will be the output of the following C code ??

#include <stdio.h>
void main()
{
int x = 5.3 % 2;
printf(“Value of x is %d”, x);
}

a) Value of x is 2.3
b) Value of x is 1
c) Value of x is 0.3
d) Compile time error

View Answer

d) Compile time error

 

Arithmetic Operators In C MCQs

 

Which among the following are the fundamental arithmetic operators, i.e, performing the desired operation can be done using that operator only ??

a) +, –
b) +, -, %
c) +, -, *, /
d) +, -, *, /, %

View Answer

a) +, –

 

What will be the final value of x in the following C code ??

#include <stdio.h>
void main()
{
int x = 5 * 9 / 3 + 9;
}

a) 3.75
b) Depends on compiler
c) 24
d) 3

View Answer

c) 24

 

Which of the following data type will throw an error on modulus operation(%) ??

a) char
b) short
c) int
d) float

View Answer

d) float

 

What will be the output of the following C code ??

#include <stdio.h>
int main()
{
int i = -5;
i = i / 3;
printf(“%d\n”, i);
return 0;
}

a) Implementation defined
b) -1
c) -3
d) Compile time error

View Answer

b) -1

 

Arithmetic Operators In C MCQs

 

Which of the following is not an arithmetic operation ??

a) a * = 10;
b) a / = 10;
c) a ! = 10;
d) a % = 10;

View Answer

c) a ! = 10;

 

What will be the output of the following C code ??

#include <stdio.h>
int main()
{
int i = 5;
i = i / 3;
printf(“%d\n”, i);
return 0;
}

a) Implementation defined
b) 1
c) 3
d) Compile time error

View Answer

b) 1

 

What is the precedence of arithmetic operators (from highest to lowest) ??

a) %, *, /, +, –
b) %, +, /, *, –
c) +, -, %, *, /
d) %, +, -, *, /

View Answer

a) %, *, /, +, –

 

Arithmetic Operators In C MCQs

 

What will be the output of the following C code ??

#include <stdio.h>
int main()
{
int i = 3;
int l = i / -2;
int k = i % -2;
printf(“%d %d\n”, l, k);
return 0;
}

a) Compile time error
b) -1 1
c) 1 -1
d) Implementation defined

View Answer

b) -1 1

 

What will be the output of the following C code ??

#include <stdio.h>
void main()
{
int a = 3;
int b = ++a + a++ + –a;
printf(“Value of b is %d”, b);
}

a) Value of x is 12
b) Value of x is 13
c) Value of x is 10
d) Undefined behaviour

View Answer

d) Undefined behaviour

 

What will be the output of the following C code ??

#include <stdio.h>
int main()
{
int i = -3;
int k = i % 2;
printf(“%d\n”, k);
}

a) Compile time error
b) -1
c) 1
d) Implementation defined

View Answer

b) -1

 

Declaration In C MCQs: MCQs On C Language Declarations

Declaration In C. MCQs on the topic of Declaration In C Programming Language.

Declaration In C MCQs

 

Which of the following declaration is not supported by C ??

a) String str;
b) char *str;
c) float str = 3e2;
d) Both String str; & float str = 3e2;

 

Which of the following statement is false ??

a) A variable defined once can be defined again with different scope
b) A single variable cannot be defined with two different types in the same scope
c) A variable must be declared and defined at the same time
d) A variable refers to a location in memory

 

The name of the variable used in one function cannot be used in another function ??

a) True
b) False

 

Which of the following is not a pointer declaration ??

a) char a[10];
b) char a[] = {‘1’, ‘2’, ‘3’, ‘4’};
c) char *str;
d) char a;

Declaration In C MCQs

 

Which of the following declaration is illegal ??

a) char *str = “Best C programming”;
b) char str[] = “Best C programming”;
c) char str[20] = “Best C programming”;
d) char[] str = “Best C programming”;

 

Which of the following format identifier can never be used for the variable var ??

#include <stdio.h>
int main()
{
char *var = “abc”;
}

a) %f
b) %d
c) %c
d) %s

 

A variable declared in a function can be used in main() ??

a) True
b) False
c) True if it is declared static
d) None of the mentioned

 

Which keyword is used to prevent any changes in the variable within a C program ??

a) immutable
b) mutable
c) const
d) volatile

Declaration In C MCQs

 

What will be the output of the following C code ??

#include <stdio.h>
void main()
{
int k = 4;
float k = 4;
printf(“%d”, k)
}

a) Compile time error
b) 4
c) 4.0000000
d) 4.4

 

What will be the output of the following C code ??

#include <stdio.h>
int main()
{
j = 10;
printf(“%d\n”, j++);
return 0;
}

a) 10
b) 11
c) Compile time error
d) 0

 

What will be the output of the following C code ??

#include <stdio.h>
int main()
{
const int i = 10;
int *ptr = &i;
*ptr = 20;
printf(“%d\n”, i);
return 0;
}

a) Compile time error
b) Compile time warning and printf displays 20
c) Undefined behaviour
d) 10

Declaration In C MCQs

 

What will be the output of the following C code ??

#include <stdio.h>
void foo(const int *);
int main()
{
const int i = 10;
printf(“%d “, i);
foo(&i);
printf(“%d”, i);
}
void foo(const int *i)
{
*i = 20;
}

a) Compile time error
b) 10 20
c) Undefined value
d) 10

 

Will the following C code compile without any error ??

#include <stdio.h>
int main()
{
int k;
{
int k;
for (k = 0; k < 10; k++);
}
}

a) Yes
b) No
c) Depends on the compiler
d) Depends on the C standard implemented by compilers

 

Will the following C code compile without any error ??

#include <stdio.h>
int main()
{
for (int k = 0; k < 10; k++);
return 0;
}

a) Yes
b) No
c) Depends on the C standard implemented by compilers
d) Error

 

Constants In C Language: MCQs On Constants in C

Constants In C Language. Learn Constants in C Language with the help of Multiple Choice Questions and Programming examples.

Constants In C Language

 

enum types are processed by ??

a) Compiler
b) Preprocessor
c) Linker
d) Assembler

 

Which of the following statement is false ??

a) Constant variables need not be defined as they are declared and can be defined later
b) Global constant variables are initialised to zero
c) const keyword is used to define constant values
d) You cannot reassign a value to a constant variable

 

What will be the output of the following C code ??

#include <stdio.h>
enum birds {SPARROW, PEACOCK, PARROT};
enum animals {TIGER = 8, LION, RABBIT, ZEBRA};
int main()
{
enum birds m = TIGER;
int k;
k = m;
printf(“%d\n”, k);
return 0;
}

a) 0
b) Compile time error
c) 1
d) 8

 

What will be the output of the following code snippet ??

#include <stdio.h>
int const print()
{
printf(“Myandroid.site”);
return 0;
}
void main()
{
print();
}

a) Error because function name cannot be preceded by const
b) Myandroid.site
c) Myandroid.site is printed infinite times
d) Blank screen, no output

Constants In C Language

 

What will be the output of the following code ??

#include <stdio.h>
#include <string.h>
int main()
{
char *str = “x”;
char c = ‘x’;
char ary[1];
ary[0] = c;
printf(“%d %d”, strlen(str), strlen(ary));
return 0;
}

a) 1 1
b) 2 1
c) 2 2
d) 1 (undefined value)

 

What will be the output of the following C code ??

#include <stdio.h>
void main()
{
int const k = 5;
k++;
printf(“k is %d”, k);
}

a) k is 6
b) Error due to const succeeding int
c) Error, because a constant variable can be changed only twice
d) Error, because a constant variable cannot be changed

 

What will be the output of the following C code ??

#include <stdio.h>
#define MAX 2
enum bird {SPARROW = MAX + 1, PARROT = SPARROW + MAX};
int main()
{
enum bird b = PARROT;
printf(“%d\n”, b);
return 0;
}

a) Compilation error
b) 5
c) Undefined value
d) 2

 

What will be the output of the following C code ??

#include <stdio.h>
void main()
{
int k = 4;
int *const p = &k;
int r = 3;
p = &r;
printf(“%d”, p);
}

a) Address of k
b) Address of r
c) Compile time error
d) Address of k + address of r

Constants In C Language

 

What will be the output of the following C code ??

#include <stdio.h>
int main()
{
int var = 010;
printf(“%d”, var);
}

a) 2
b) 8
c) 9
d) 10

 

What will be the output of the following C code ??

#include <stdio.h>
int main()
{
const int p;
p = 4;
printf(“p is %d”, p);
return 0;
}

a) p is 4
b) Compile time error
c) Run time error
d) p is followed by a garbage value

 

What will be the output of the following C code ??

#include <stdio.h>
#define a 10
int main()
{
const int a = 5;
printf(“a = %d\n”, a);
}

a) a = 5
b) a = 10
c) Compilation error
d) Runtime error

 

What will be the output of the following code ??

#include <stdio.h>
int main()
{
printf(“myandroid\r\nclass\n”);
return 0;
}

a) myandroid

b) myandroid
class

c) myandroid

d) myandroid,myandroid

Constants In C Language

 

What will be the output of the following code snippet ??

#include <stdio.h>
int main()
{
printf(“myandroid\rclass\n”);
return 0;
}

a) myandroidclass

b) myandroid
class

c) classmyandroid

d) myandroid, myandroid

 

What will be the output of following code ??

#include <stdio.h>
int main()
{
printf(“C programming %s”, “Class by\n%s Myandroid”, “WOW”);
}

a) C programming Class by
WOW Myandroid

b) C programming Class by\n%s Myandroid

c) C programming Class by
%s Myandroid

d) Compilation error

 

What will be the output of the following C code ??

#include <stdio.h>
int main()
{
enum {ORANGE = 5, MANGO, BANANA = 4, PEACH};
printf(“PEACH = %d\n”, PEACH);
}

a) PEACH = 3
b) PEACH = 4
c) PEACH = 5
d) PEACH = 6

 

In the following code snippet character pointer str holds a reference to the string ??

char *str = “Myandroid.site\0” “training classes”;

a) Myandroid.site
b) Myandroid.site\0training classes
c) Myandroid.site training classes
d) Invalid declaration

 

Data Types in C Programming: MCQs On Data Types in C

Data Types in C Programming. MCQs on the topic of Data Types in C programming Language.

Data Types in C Programming

 

What is short int in C programming ??

a) The basic data type of C
b) Qualifier
c) Short is the qualifier and int is the basic data type
d) All of the mentioned

 

Which of the data types has the size that is variable ??

a) int
b) struct
c) float
d) double

 

What is the size of an int data type ??

a) 4 Bytes
b) 8 Bytes
c) Depends on the system/compiler
d) Cannot be determined

 

Which is correct with respect to the size of the data types ??

a) char > int > float
b) int > char > float
c) char < int < double
d) double > char > int

Data Types in C Programming

 

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

 

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

 

What will be the output of the following 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

 

What will be the output of the following C code ??

#include <stdio.h>
int main()
{
float x = ‘a’;
printf(“%f”, x);
return 0;
}

a) a
b) run time error
c) a.0000000
d) 97.000000

Data Types in C Programming

 

What will be the output of the following 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

 

What will be the output of the following C code ??

#include <stdio.h>
int main()
{
float f1 = 0.1;
if (f1 == 0.1f)
printf(“equal\n”);
else
printf(“not equal\n”);
}

a) equal
b) not equal
c) output depends on compiler
d) error

 

What will be the output of the following 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 the compiler
d) error

 

What will be the output of the following C code ??

#include <stdio.h>
int main()
{
int a[5] = {1, 2, 3, 4, 5};
int i;
for (i = 0; i < 5; i++)
if ((char)a[i] == ‘5’)
printf(“%d\n”, a[i]);
else
printf(“FAIL\n”);
}

a) The compiler will flag an error
b) The program will compile and print the output 5
c) The program will compile and print the ASCII value of 5
d) The program will compile and print FAIL for 5 times

Data Types in C Programming

 

What will be the output of the following C code on a 64 bit machine ??

#include <stdio.h>
union Sti
{
int nu;
char m;
};
int main()
{
union Sti s;
printf(“%d”, sizeof(s));
return 0;
}

a) 8
b) 5
c) 9
d) 4

 

What will be the output of the following C code on a 32-bit machine ??

#include <stdio.h>
int main()
{
int x = 10000;
double y = 56;
int *p = &x;
double *q = &y;
printf(“p and q are %d and %d”, sizeof(p), sizeof(q));
return 0;
}

a) p and q are 4 and 4
b) p and q are 4 and 8
c) compiler error
d) p and q are 2 and 8

 

The format identifier ‘%i’ is also used for _____ data type ??

a) char
b) int
c) float
d) double

 

Variables In C Language: MCQs on C Programming Variables

Variables In C Language. Multiple Choice Questions on the topic of Variables In C Language.

Variables In C Language

 

All keywords in C are in ??

a) Lowercase letters
b) Uppercase letters
c) CamelCase letters
d) None of the mentioned

 

Which of the following is not a valid variable name declaration ??

a) int __a3;
b) int __3a;
c) int __A3;
d) None of the mentioned

 

Which of the following is not a valid C variable name ??

a) int number;
b) float rate;
c) int variable_count;
d) int $main;

 

Which of the following is not a valid variable name declaration ??

a) int _a3;
b) int a_3;
c) int 3_a;
d) int _3a

Variables In C Language

 

Which of the following is true for variable names in C ??

a) They can contain alphanumeric characters as well as special characters
b) It is not an error to declare a variable to be one of the keywords(like goto, static)
c) Variable names cannot start with a digit
d) Variable can be of any length

 

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

 

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;

 

What will be the output of the following C code ??

#include <stdio.h>

int main()
{
printf(“Hello World! %d \n”, x);
return 0;
}

Hello World! x;
b) Hello World! followed by a junk value
c) Compile time error
d) Hello World!

Variables In C Language

 

Which of the following cannot be a variable name in C ??

a) volatile
b) true
c) friend
d) export

 

What will be the output of the following 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

 

What will be the output of the following 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

 

C99 standard guarantees uniqueness of _____ characters for external names ??

a) 31
b) 6
c) 12
d) 14

Variables In C Language

 

C99 standard guarantees uniqueness of __________ characters for internal names ??

a) 31
b) 63
c) 12
d) 14

 

Why do variable names beginning with the underscore is not encouraged ??

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

 

Variable name resolution number of significant characters for the uniqueness of variable depends on ??

a) Compiler and linker implementations
b) Assemblers and loaders implementations
c) C language
d) None of the mentioned

Variables In C Language

 

What will happen if the following C code is executed ??

#include <stdio.h>

int main()
{
int main = 3;
printf(“%d”, main);
return 0;
}

a) It will cause a compile-time error
b) It will cause a run-time error
c) It will run without any error and prints 3
d) It will experience infinite looping

 

What is the problem in the 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

 

Data Types In C Language: C Programming MCQ

Data Types In C Language. 20+ Multiple-Choice Questions on C Language Data Types.

C Data Types MCQ

 

Sizes of short, int, and long in a Turbo C C++ compiler in bytes are ??

A) 2, 2, 4
B) 2, 4, 4
C) 4, 8, 16
D) 8, 8, 16

 

A register variable is stored in a Register. Where does a Register Present in a Computer ??

A) RAM ( Random Access Memory )
B) ROM ( Read Only Memory )
C) CPU (Central Processing Unit )
D) DMA ( Direct Memory Access )

 

Sizes of short, int, and long in Visual Studio or GCC compiler in bytes are ??

A) 2, 2, 4
B) 2, 4, 4
C) 4, 4, 8
D) 4, 8, 8

 

Identify which of the following are declarations ??
1 : extern int x;
2 : float square ( float x ) { … }
3 : double pow(double, double);

A. 1
B. 2
C. 1 and 3
D. 3

 

Range of signed char and unsigned char are ??

A) -128 to +127 / 0 to 255
B) 0 to 255 / -128 to +127
C) -128 to -1 / 0 to +127
D) 0 to +127 / -128 to -1

 

C Language MCQ

 

Select the true statement ??

A) Variables of type auto are stored in Stack memory
B) Variable of type Static is stored in Segmented Memory
C) Variables of type register are stored in Micro Processor Memory
D) All the above

 

Ranges of signed int and unsigned int are ??

A) 0 to 65535 / -32768 to +32767
B) -32768 to +32767 / 0 to 65535
C) -32767 to +32768 / 0 to 65536
D) 0 to 65536 / -32767 to +32768

 

Variables of type auto, static and extern are all stored in ??

A) ROM
B) RAM
C) CPU
D) Compiler

 

Size of float, double and long double in Bytes are ??

A) 4, 8, 16
B) 4, 8, 10
C) 2, 4, 6
D) 4, 6, 8

 

Which among the following is a Local Variable ??

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

 

C Data Types MCQ

 

Range of singed long and unsigned long variables are ??
A) -2147483647 to +2147483648 0 to 4294967295
B) -2147483648 to +2147483647 0 to 4294967296
C) -2147483648 to +2147483647 0 to 4294967295
D) 0 to 4294967295 -2147483648 to +2147483647

 

Which among the following is a Global Variable ??

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

 

The range of float variable is ??

A) -3.2e38 to +3.2e38
B) -3.8e32 to +3.8e32
C) -3.4e34 to +3.4e34
D) -3.4e38 to +3.4e38

 

Which one of the following is correct ??

A) Register variables are usually fast retrieving variables
B) Static variables usually maintain their values between function calls
C) Auto variables release their memory after the block or function where they are declared
D) All the above

 

Leftmost bit 0 in Singed representation indicates ??

A) A Positive number
B) A Negative Number
C) An Unsigned number
D) None of the above

 

C Data Types MCQ

 

Choose a correct statement about the static variables ??

A) We can access a static global variable in other files
B) A static global variable can be used only in a file in which it is declared
C) A static global variable can not be declared without an extern keyword
D) Default value of a static variable is -1

 

If you do not specify a storage class for a Variable ??

A) You get a compiler error.
B) You get a compiler warning.
C) Output is null always
D) None of the above

 

What is the difference between Declaration and Definition ??
A) Declaration does allocate memory for a variable
The definition does allocate memory for a variable

B) Declaration does allocate memory for a variable
The definition does not allocate memory for a variable

C) Declaration does not allocate memory for a variable
The definition does allocate memory for a variable

D) Declaration does not allocate memory for a variable
The definition does not allocate memory for a variable

 

Choose the right statement ??

A) We don’t use a non-static global variable in included files
B) A non-static global variable can be used or referred to inside included files
C) A non-static global variable does not live till the end of program execution
D) None of the above

 

Choose the right statement ??

A) Redeclaration of a variable is Ok
B) Redefinition of a variable is not Ok
C) Definition of a variable uses memory blocks
D) All the above

 

Related Posts

String In C MCQ: Multiple Choice Questions Strings

String In C MCQ. Mixed Multiple-Choice Questions on Strings and its types with Programs and Outputs.

String In C MCQ

 

Which of the following function duplicates a string ??

A. strnset
B. strstr
C. strdup
D. stricmp

 

Which string method helps find the length of the string ??

A. stringLength()
B. strlen
C. strdup
D. both i & ii

 

What is a String in C Language ??

A. String is a new Data Type in C
B. String is an array of Characters with null characters as the last element of an array
C. String is an array of Characters with null character as the first element of the array
D. String is an array of Integers with 0 as the last element of the array

 

Which of the following is format specification for printing String in printf() ??

A. %d
B. %c
C. %f
D. %s

 

A String constant in C terminated by ??

A. ‘\O’
B. ‘\\O’
C. “
D. ” “

String In C MCQ

 

Choose a correct statement about C String ??

char ary[]=”Hello..!”;

A. Character array, ary is a string
B. ary has no Null character at the end
C. String size is not mentioned
D. String can not contain special characters

 

A string in C is what ??

A. 1-D Array of Character
B. 2-D Array of Character
C. Any of i & ii
D. None of the above

 

int len = strlen (“Alan Poonam) ;
printf(“%s” , len) ;

What would be value of len printed ??

A. 10
B. 11
C. depends on the compiler
D. None of the above

 

What is the Format specifier used to print a String or Character array in C Printf or Scanf function ??
A. %c
B. %C
C. %s
D. %w

 

What C function copies the content of one String into another ??

A. Ssrcopy()
B. stringcopy()
C. strcpy()
D. both i & iI

C Language MCQs

 

What is the output of the C Program with Strings ??

int main()
{
char ary[]=”Discovery Channel”;
printf(“%s”,ary);
return 0;
}

A. D
B. Discovery Channel
C. Discovery
D. Compiler error

 

This C function copies the content of the source string at the end of the target string ??

A. copycat()
B. strcat()
C. both
D. None of the above

 

What is the output of the C Program ??

int main()
{
char str[]={‘g’,’l’,’o’,’b’,’e’};
printf(“%s”,str);
return 0;
}

A. g
B. globe
C. globe\0
D. None of the above

 

All the characters in the string are stored in ??

A. contiguous memory location
B. discreet memory location
C. both
D. pointer to pointer

 

What would be the output of the C Program with ??

int main()
{
char str[]={‘g’,’l’,’o’,’b’,’y’,’\0′};
printf(“%s”,str);
return 0;
}

A. g
B. globe
C. globe\0
D. Compiler error

String In C MCQ

 

A one-dimensional array A has indices 1….75. Each element is a string and takes up three memory words. The array is stored at location 1120 decimal. The starting address of A[49] is ??

A. 1264
B. 1164
C. 1167
D. 1267

 

How do you convert this char array to string ??

char str[]={‘g’,’l’,’o’,’b’,’y’};

A. str[5] = 0;
B. str[5] = ‘\0’
C. str[]={‘g’,’l’,’o’,’b’,’y’,’\0′};
D. All the above

 

The string processing-related functions are stored in which header file ??

A. <stdio.h>
B. <conio.h>
C. <string.h>
D. none of these

 

What is the maximum number of dimensions an array in C may have ??

A. Two
B. eight
C. sixteen
D. Theoretically no limit. The only practical limits are memory size and compilers

 

Which in-built function can be used to concatenate given two strings in the C program ??

A. strlen( )
B. strcat( )
C. strstr( )
D. none of these

String In C MCQ

 

What is the output of the given Program ??

int main()
{
int str[]={‘g’,’l’,’o’,’b’,’y’};
printf(“A%c “,str);
printf(“A%s “,str);
printf(“A%c “,str[0]);
return 0;
}

A. A A A
B. A Ag Ag
C. A*randomchar* Ag Ag
D. Compiler error

 

What will be the address of the arr[2][3] if arr is a 2-D long array of 4 rows and 5 columns and the starting address of the array is 2000 ??

A. 2048
B. 2056
C. 2052
D. 2042

 

Predict the output ??
#include<string.h>
void main()
{
char str1[10]=”abyz”;
int i;
for(i=0; i<4; i++)
{
printf(“%c”,str1[i] – 32);
}
}

A. AB
B. zyba
C. abyz
D. ABYZ

 

What is the output of the C Program with arrays ??

int main()
{
char str[]={“C”,”A”,”T”,”\0″};
printf(“%s”,str);
return 0;
}

A. C
B. CAT
C. CAT\0
D. Compiler error

 

An array can be considered as a set of elements stored in consecutive memory locations but having ??

A. Same data type
B. Different data type
C. Same scope
D. None of these

String In C MCQ

 

What is the output ??
#include<string.h>
int main()
{
char str1[50]=”abc”, str2[50];
strcpy(str2, strrev(str1));
printf(“Reverse string is : %s”,str2);
return 0;
}

A. abc
B. cba
C. ABC
D. none of these

 

What is the maximum length of a C String ??

A. 32 characters
B. 64 characters
C. 256 characters
D. None of the above

Size of the array need not be specified, when ??

A. Initialization is a part of the definition
B. It is a formal parameter
C. It is a declaratrion
D. All of the above

 

What is the output of the C program with strings ??

int main()
{
char str1[]=”JOHN”;
char str2[20];
str2= str1;
printf(“%s”,str2);
return 0;
}

A. JOHN
B. J
C. JOHN\0
D. Compiler error

 

The information about an array used in the program will be stored in ??

A. Symbol Table
B. Activation Record
C. Dope Vector
D. Both A and B

String In C MCQ

 

What is the output of the C Program with arrays ??

int main()
{
char str[25];
scanf(“%s”, str);
printf(“%s”,str);
return 0;
}
//input: South Africa

A. South
B. South Africa
C. S
D. Compiler error

 

The parameter passing mechanism for an array is ??

A. call by value
B. call by reference
C. call by value-result
D. None of the above

 

What is the output of the C program with strings ??

int main()
{
char str[2];
scanf(“%s”, str);
printf(“%s”,str);
return 0;
}
//Input: South

A. So
B. South
C. Compiler error
D. None of the above

 

What is the output of this program ??

int main()
{
char country[]=”BRAZIL”;
char *ptr;
ptr=country;
while(*ptr != ‘\0’)
{
printf(“%c”, *ptr);
ptr++;
}
return 0;
}

A. B
B. BRAZIL
C. Compiler error
D. None of the above

 

A string that is a formal parameter can be declared ??

A. An array with empty braces
B. A pointer to a character
C. Both A and B
D. None of the above

String In C MCQ

 

What is the output of the C Program with strings ??
int main()
{
char str[2];
int i=0;
scanf(“%s”, str);
while(str[i] != ‘\0’)
{
printf(“%c”, str[i]);
i++;
}
return 0;
}
//Input: KLMN

A. KL
B. KLMN
C. Compiler error
D. None of the above

 

Strcat function adds null character ??

A. Only if there is space
B. Always
C. Depends on the standard
D. depends on the compiler

 

How do you accept a Multi-Word Input in C Language ??

A. SCANF
B. GETS
C. GETC
D. FINDS

 

What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of the array ??

A. The element will be set to 0.
B. The compiler would report an error.
C. The program may crash
D. None of the above

 

Choose a correct C Statement about Strings ??

A. PRINTF is capable of printing a multi-word string.
B. PUTS is capable of printing a multi-word string.
C. GETS is capable of accepting a multi-word string from the console or command prompt
D) All the above

 

Array In C programming MCQs: Multiple-Choice Questions

Array In C programming MCQs. Arrays Related Multiple-Choice Questions in C Programming. See all C language MCQs on all topics

Array In C programming

 

What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of the array ??

A. The element will be set to 0
B. The compiler would report an error
C. The program may crash if some important data gets overwritten
D. The array size would appropriately grow

 

What does the following declaration mean ??
int (*ptr)[10];

A. ptr is an array of pointers to 10 integers
B. ptr is a pointer to an array of 10 integers
C. ptr is an array of 10 integers
D. ptr is a pointer to an array

 

What will be the output of the program ??

#include<stdio.h>
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf(“%d, %d, %d”, i, j, m);
return 0;
}

A. 2, 1, 15
B. 1, 2, 5
C. 3, 2, 15
D. 2, 3, 20

 

In C, if you pass an array as an argument to a function, what actually gets passed ??

A. Value of elements in the array
B. First element of the array
C. Base address of the array
D. Address of the last element of the array

Arrays

 

Which of the following statements mentioning the name of the array begins DOES NOT yield the base address ??
1: When array name is used with the sizeof operator.
2: When array name is an operand of the & operator.
3: When array name is passed to scanf() function.
4: When array name is passed to printf() function.

A. A
B. A, B
C. B
D. B, D

What will be the output of the program ??

#include<stdio.h>

int main()
{
static int a[2][2] = {1, 2, 3, 4};
int i, j;
static int *p[] = {(int*)a, (int*)a+1, (int*)a+2};
for(i=0; i<2; i++)
{
for(j=0; j<2; j++)
{
printf(“%d, %d, %d, %d\n”, *(*(p+i)+j), *(*(j+p)+i),
*(*(i+p)+j), *(*(p+j)+i));
}
}
return 0;
}

A. 1, 1, 1, 1
2, 3, 2, 3
3, 2, 3, 2
4, 4, 4, 4

B. 1, 2, 1, 2
2, 3, 2, 3
3, 4, 3, 4
4, 2, 4, 2

C. 1, 1, 1, 1
2, 2, 2, 2
2, 2, 2, 2
3, 3, 3, 3

D. 1, 2, 3, 4
2, 3, 4, 1
3, 4, 1, 2
4, 1, 2, 3

 

Which of the following statements are correct about 6 in the code given ??
int num[6];
num[6]=21;

A. In the first statement, 6 specifies a particular element, whereas in the second statement it specifies a type
B. In the first statement 6 specifies an array size, whereas in the second statement it specifies a particular element of the array
C. In the first statement 6 specifies a particular element, whereas in the second statement it specifies an array size
D. In both the statement 6 specifies array size

 

What will be the output of the program ??

#include<stdio.h>
void fun(int **p);
int main()
{
int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0};
int *ptr;
ptr = &a[0][0];
fun(&ptr);
return 0;
}
void fun(int **p)
{
printf(“%d\n”, **p);
}

A. 1
B. 2
C. 3
D. 4

Array In C programming

 

Which of the following statements are correct about an array ??
1: The array int num[26]; can store 26 elements
2: The expression num[1] designates the very first element in the array
3: It is necessary to initialize the array at the time of declaration
4: The declaration num[SIZE] is allowed if SIZE is a macro

A. 1
B. 1,4
C. 2,3
D. 2,4

 

Does the array name give the base address in all the contexts ??

A. Yes
B. No

What will be the output of this program ??

#include<stdio.h>
int main()
{
int arr[5], i=0;
while(i<5)
arr[i]=++i;

for(i=0; i<5; i++)
printf(“%d, “, arr[i]);

return 0;
}

A. 1, 2, 3, 4, 5,
B. Garbage value, 1, 2, 3, 4,
C. 0, 1, 2, 3, 4,
D. 2, 3, 4, 5, 6,

A pointer to a block of memory is effectively the same as an array ??

A. True
B. False

Array In C programming

 

What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes ??

#include<stdio.h>
int main()
{
int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};
printf(“%u, %u\n”, a+1, &a+1);
return 0;
}

A. 65474, 65476
B. 65480, 65496
C. 65480, 65488
D. 65474, 65488

 

Both declarations look similar but, is there any difference in these declarations ??
int fun(int arr[]);
int fun(int arr[2]);

A. Yes
B. No

 

What will be the output of the program ??

#include<stdio.h>
int main()
{
int arr[1]={10};
printf(“%d\n”, 0[arr]);
return 0;
}

A. 1
B. 10
C. 0
D. 6

 

Are the expressions arr and &arr the same for an array of 10 integers ??

A. Yes
B. No

Array In C programming

 

What will be the output of the program ??

#include<stdio.h>
int main()
{
float arr[] = {12.4, 2.3, 4.5, 6.7};
printf(“%d\n”, sizeof(arr)/sizeof(arr[0]));
return 0;
}

A. 5
B. 4
C. 6
D. 7

 

What is the effect of the following code ??

main()
{
int a[4]={1,5};
printf(“%d”,a[3]);
}

A. 0
B. Syntax error because of improper initialization
C. 5
D. Syntax error because of invalid index

 

The size of the array should always be ??

A. Positive
B. Negative
C. Whole number
D. Real number

 

What is the meaning of the following declaration ??

int arr[20];

A.Integer Array of size 20
B.None of these
C.An array of size 20 that can have an integer address
D.An array of Size 20

Array In C programming

 

For the following definition, which of the given option is correct ??

int a[10];

A. a++;
B. a=a+1
C. *a++
D. *a[1]

 

int a[50];
int *pa;
pa=a;

To access the 6th element of the array which of the following is incorrect ??

A. *(a+5)
B. a[5]
C. pa[5]
D. *(*pa+5)

 

C Language MCQs: C Programming MCQ Part-2

C Language MCQs. Mix C Language Multiple-Choice Questions on Various C topics including Pointers, Values, Initialization, Functions, and Varibles.

 

C Language MCQs

 

The operator used to get value at address stored in a pointer variable is ??

a. *
b. &
c. &&
d. ||

 

A function may have any number of return statements each returning different values ??

a. True
b. False

 

Which of the following statements correctly declare a function that receives a pointer to pointer to a pointer to a float and returns a pointer to a pointer to a pointer to a pointer to a float ??

a. float **fun(float***);
b. float *fun(float**);
c. float fun(float***);
d. float ****fun(float***);

 

Names of functions in two different files linked together must be unique ??

a. True
b. False

 

Are the expression *ptr++ and ++*ptr are same ??

a. True
b. False

 

Functions cannot return a floating-point number ??

a. Yes
b. No

 

Are the three declarations char **apple, char *apple[], and char apple[][] same ?

a. True
b. False

 

Every function must return a value ??

a. Yes
b. No

 

Is there any difference between the following two statements ??
char *p=0;
char *t=NULL;

a. Yes
b. No

 

If a function contains two return statements successively, the compiler will generate warnings. Yes/No ??

a. Yes
b. No

 

C Multiple Choice Questions

 

Is this the correct way for the NULL pointer assignment ??
int i=0;
char *q=(char*)i;

a. Yes
b. No

 

The maximum number of arguments that a function can take is 12 ??

a. Yes
b. No

 

Is the NULL pointer the same as an uninitialized pointer ??

a. Yes
b. No

 

Usually, recursion works slower than loops ??

a. Yes
b. No

 

Which of the following function sets the first n characters of a string to a given character ??

a. strinit()
b. strnset()
c. strset()
d. strcset()

 

Is it true that too many recursive calls may result in stack overflow ??

a. Yes
b. No

 

If the two strings are identical, then strcmp() function returns ??

a. -1
b. 1
c. 0
d. Yes

 

In a function two return statements should never occur ??

a. Yes
b. No

 

How will you print on the screen ??

a. printf(” “);
b. echo “\n”;
c. printf(‘ ‘);
d. printf(“\n”)

 

What is (void*)0 ??

a. Representation of NULL pointer
b. Representation of void pointer
c. Error
d. None of above

 

C Language MCQs

 

The library function used to find the last occurrence of a character in a string is ??

a. strnstr()
b. laststr()
c. strrchr()
d. strstr()

 

Can you combine the following two statements into one ??

a. char p = *malloc(100);
b. char *p = (char) malloc(100);
c. char *p = (char*)malloc(100);
d. char *p = (char *)(malloc*)(100);

 

Which of the following function is used to find the first occurrence of a given string in another string ??

a. strchr()
b. strrchr()
c. strstr()
d. strnset()

 

In which header file is the NULL macro defined ??

a. stdio.h
b. stddef.h
c. stdio.h and stddef.h
d. math.h

 

Which of the following function is more appropriate for reading in a multi-word string ??

a. printf();
b. scanf();
c. gets();
d. puts();

 

Which of the following statements are correct about the below declarations ??
char *p = “myAndroid”;)
char a[] = “myAndroid”;)
1: There is no difference in the declarations and both serve the same purpose
2: p is a non-const pointer pointing to a non-const string, whereas a is a const pointer pointing to a non-const pointer
3: The pointer p can be modified to point to another string, whereas the individual characters within array a can be changed
4: In both cases, the ” will be added at the end of the string “myAndroid”

a. 1, 2
b. 2, 3, 4
c. 3, 4
d. 2, 3

 

C Language MCQs

 

Which of the following statement is correct ??

a. strcmp(s1, s2) returns a number less than 0 if s1>s2
b. strcmp(s1, s2) returns a number greater than 0 if s1 c. strcmp(s1, s2) returns 0 if s1==s2
c. strcmp(s1, s2) returns 1 if s1==s2
d. None of these

 

While calling the print() function in the format string conversion specifier %s can be used to write a character string in capital letters ??

a. True
b. False

 

For the following statements will arr[3] and ptr[3] fetch the same character ??
har arr[] = “myAndroid”;)
char *ptr = “myAndroid”;)

a. Yes
b. No

 

A text stream is an ordered sequence of characters composed of lines, each line consisting of zero or more characters plus a terminating new-line character ??

a. True
b. False

 

Is there any difference between the two statements ??
char *ch = “myAndroid”;)
char ch[] = “myAndroid”;)

a. Yes
b. No

 

The offset used in fseek() function call can be a negative number ??

a. True
b. False

 

C Language MCQs

 

a file contains the line “I am a boy” then on reading this line into the array str using gets(). What will str contain ??

a. “I am a boy “
b. “I am a boy “
c. “I am a boy “
d. “I am a boy”

 

We should not read after a write to a file without an intervening call to fflush(), fseek() or rewind() ??

a. True
b. False

 

To print out a and b were given below, which of the following printf() statements will you use ??
#include
float a=3.14;
double b=3.14;

a. printf(“%f %lf”, a, b);
b. printf(“%Lf %f”, a, b);
c. printf(“%Lf %Lf”, a, b);
d. printf(“%f %Lf”, a, b);

 

In a call to printf() function the format specifier %b can be used to print binary equivalent of an integer ??

a. True
b. False

 

To scan a and b were given below, which of the following scanf() statement will you use ??
#include
float a;
double b;

a. scanf(“%f %f”, &a, &b);
b. scanf(“%Lf %Lf”, &a, &b);
c. scanf(“%f %Lf”, &a, &b);
d. scanf(“%f %lf”, &a, &b);

 

stderr, stdin, stdout are FILE pointers ??

a. Yes
b. No

 

 

Out of fgets() and gets() which function is safe to use ??

a. gets()
b. fgets()

 

C Language MCQs

 

A file written in text mode can be read back in binary mode ??

a. Yes
b. No

 

Can we specify a variable field width in a scanf() format string ??

a. Yes
b. No

 

More C Related Posts

error: Content is protected !!