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
More Posts