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

 

More Posts

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!