Interview Questions Loop C Programming For Enginnering Students Basics Viva Tutorials
https://ingenuitydias.blogspot.com/2015/07/interview-questions-loop-c-programming.html
1.Which is the correct statement?
a) Printf(“Maximum = %d\n”, (x.y) ? x : y);
b) Printf( “%s\n”, (mark >= 60) ? “First class” : “Not first class” );
c) Printf(“%s\n”, PASS);
d) All of the above
ANSWER: D
2.Do-While loop terminates when conditional expression returns?
a) Zero
b) One
c) Non-zero
d) -1
ANSWER: A
3.In the following loop construct, which one is executed only once always.
for ( exp1; exp2; exp3) {. . . }
a) exp1
b) exp3
c) exp1 and exp3
d) exp1, exp2 and exp3
ANSWER: A
4. if default statement is omitted and there is no match with the case table
a) No statement within switch case will be executed
b) Syntax error is produced
c) Executes all the statements in the switch case construct
d) Executes the last case statement only
ANSWER: A
5.What will be printed when the above code is executed?
main()
{
int a = 2, b = 4, c = 8, x = 4;
if ( x == b) x = a; else x = b;
if( x != b) c = c + b; else c = c + a;
printf(“c = %d\n”,c);
}
a) C = 4
b) C = 8
c) C = 10
d) C = 12
ANSWER: D
6.What will be the output of above sample code?
main()
{
unsigned int x = -10; int y = 10;
If ( y <= x) printf( “He is good\n”);
If ( y == ( x = -10)) printf( “She is better\n”);
If (( int) x == y) printf(“it is the best\n”);
}
a) She is better
b) He is good it is the best
c) It is the best
d) He is good
ANSWER: D
7.What will be the value of x so that “Karthik” will be printed?
main()
{
int x;
if ( x > 4) printf( “Brinda”);
else if ( x > 10) printf( “Karthik”);
else if ( x > 21 ) printf(“ Pradeep”);
else printf( “Sandeep”);
}
a) From 10 to 21
b) From 11 to 21
c) Grater then 10
d) None
ANSWER: D
8.What will be printed when the above code is executed?
main()
{
int x = 0;
for (; ;)
{
if ( x++ == 4) break;
continue;
}
printf(“x = %d\n”, x);
}
a) X = 0
b) X = 1
c) X = 4
d) X = 5
ANSWER: D
9.What is the output of the following code?
main()
{
int I = 0;
switch ( I )
{
case 0 : i++;
case 1 : i+++2
case2 : ++I;
}
printf(“%d”, i++);
}
a) 1
b) 3
c) 4
d) 5
ANSWER: B
10.If the input is “1a1b1c” what is the output?
main()
{
int ones, twos, threes, others;
int c;
Ones = twos = threes = others = 0;
while( ( c = getchar() != ‘\n’) )
{
switch( c )
{
case ‘1’ : ++ones;
case ‘2’ : ++twos;
case ‘3’ : ++threes;
break;
default: ++others;
break;
}
}
printf( “%d%d ”, ones, others);
}
a) 13
b) 34
c) 33
d) 31
ANSWER: C
11.Identify the trigraph sequence for ^.
a) ?? /
b) ?? =
c) ?? ’
d) ?? !
ANSWER: C
12.What will be printed when the function above is called with pointer to a open file that contains the three characters abc?
void listFile(FILE *f)
{
int c;
While( c = fgetc( f ) != EOF)
{
printf(“%d”, c);
}
printf(“\n”);
}
a) The character ab followed by infinite no of c’s.
b) 1 1 1
c) a b c
d) 0 0 0
ANSWER: B
13.Which of the following could print the ???? in the code above to cause the function to print the length of the file when a valid file name is passed to it?
void getFileLength( char *s)
{
FILE *f;
if( f = fopen( s, “r”) )
{
fseek(f, SEEK_SET, 2);
printf(“%d\n”, ????);
fclose();
}
}
a) ftell( f )
b) fposition( f )
c) tell( f )
d) filelen( f )
ANSWER: A
14.Which of the following preprocessor directive will make the system- dependent constant INT_MAX available for ANSI C compiler?
a) #include <limits.h>
b) #include <int.h>
c) #include <ctype.h>
d) #define INT_MAX
ANSWER: A
15.After a library function returns a failure, which of the following will print out the appropriate error message corresponding to error number given by errno?
a) printf( stderr, “%s\n”, geterror () );
b) printer();
c) perror( errno).
d) strerror( errno).
ANSWER: D
16.Undefined functions calls in a c program are detected by
a) The preprocessor
b) The assembler
c) The linker
d) The operating system
ANSWER: C
17.What would be the output if the following program (myprog.c) is run using the following command line?
myprog jan feb mar apr
main( int size, char *arg[])
{
while( size ) printf(“%s”, arg[ --size ]);
}
a) myprog jan feb mar apr
b) apr mar feb jan myprog
c) jan feb mar apr
d) error
ANSWER: B
18.Study the following statement
#define DELAYTIME 1000
volatile extern int k;
int j;
for( i = 0; i < DELAYTIME; i++)
j = k;
state which of the following is true.
a) Volatile is meaningless for the variable k
b) Volatile is meaningful for the variable k since k is external and can change
c) Volatile is meaningless for the variable since k is loop variant
d) None
ANSWER: B
19.What is the output when the program is executed as prog arg 1?
Main ( int x, char *y[])
{
Printf(“%d %s”, x, y[1]);
}
a) 1 prog
b) 1 arg1
c) 2 prog
d) 2 arg1
ANSWER: D
20.The purpose of the following code is to find
#include <time.h>
main()
{
time_t t1, t2;
clock_t clock( void);
int I, x = 0, y = 10;
t1 = clock( );
for( I = 0; I < 10000; i++)
{
x++; y+ = 50;
printf(“the value of I = %d, x = %d, y = %d\n”, I, x, y);
}
t2 = clock( );
printf(“Time in seconds : %g\n”, difftime(t2, t1)/ CLOCKS_PER_SEC);
}
a) Compilation time
b) Execution time
c) Difference between GST and IST
d) Difference between compilation and execution time.
ANSWER: B
a) Printf(“Maximum = %d\n”, (x.y) ? x : y);
b) Printf( “%s\n”, (mark >= 60) ? “First class” : “Not first class” );
c) Printf(“%s\n”, PASS);
d) All of the above
ANSWER: D
2.Do-While loop terminates when conditional expression returns?
a) Zero
b) One
c) Non-zero
d) -1
ANSWER: A
3.In the following loop construct, which one is executed only once always.
for ( exp1; exp2; exp3) {. . . }
a) exp1
b) exp3
c) exp1 and exp3
d) exp1, exp2 and exp3
ANSWER: A
4. if default statement is omitted and there is no match with the case table
a) No statement within switch case will be executed
b) Syntax error is produced
c) Executes all the statements in the switch case construct
d) Executes the last case statement only
ANSWER: A
5.What will be printed when the above code is executed?
main()
{
int a = 2, b = 4, c = 8, x = 4;
if ( x == b) x = a; else x = b;
if( x != b) c = c + b; else c = c + a;
printf(“c = %d\n”,c);
}
a) C = 4
b) C = 8
c) C = 10
d) C = 12
ANSWER: D
6.What will be the output of above sample code?
main()
{
unsigned int x = -10; int y = 10;
If ( y <= x) printf( “He is good\n”);
If ( y == ( x = -10)) printf( “She is better\n”);
If (( int) x == y) printf(“it is the best\n”);
}
a) She is better
b) He is good it is the best
c) It is the best
d) He is good
ANSWER: D
7.What will be the value of x so that “Karthik” will be printed?
main()
{
int x;
if ( x > 4) printf( “Brinda”);
else if ( x > 10) printf( “Karthik”);
else if ( x > 21 ) printf(“ Pradeep”);
else printf( “Sandeep”);
}
a) From 10 to 21
b) From 11 to 21
c) Grater then 10
d) None
ANSWER: D
8.What will be printed when the above code is executed?
main()
{
int x = 0;
for (; ;)
{
if ( x++ == 4) break;
continue;
}
printf(“x = %d\n”, x);
}
a) X = 0
b) X = 1
c) X = 4
d) X = 5
ANSWER: D
9.What is the output of the following code?
main()
{
int I = 0;
switch ( I )
{
case 0 : i++;
case 1 : i+++2
case2 : ++I;
}
printf(“%d”, i++);
}
a) 1
b) 3
c) 4
d) 5
ANSWER: B
10.If the input is “1a1b1c” what is the output?
main()
{
int ones, twos, threes, others;
int c;
Ones = twos = threes = others = 0;
while( ( c = getchar() != ‘\n’) )
{
switch( c )
{
case ‘1’ : ++ones;
case ‘2’ : ++twos;
case ‘3’ : ++threes;
break;
default: ++others;
break;
}
}
printf( “%d%d ”, ones, others);
}
a) 13
b) 34
c) 33
d) 31
ANSWER: C
11.Identify the trigraph sequence for ^.
a) ?? /
b) ?? =
c) ?? ’
d) ?? !
ANSWER: C
12.What will be printed when the function above is called with pointer to a open file that contains the three characters abc?
void listFile(FILE *f)
{
int c;
While( c = fgetc( f ) != EOF)
{
printf(“%d”, c);
}
printf(“\n”);
}
a) The character ab followed by infinite no of c’s.
b) 1 1 1
c) a b c
d) 0 0 0
ANSWER: B
13.Which of the following could print the ???? in the code above to cause the function to print the length of the file when a valid file name is passed to it?
void getFileLength( char *s)
{
FILE *f;
if( f = fopen( s, “r”) )
{
fseek(f, SEEK_SET, 2);
printf(“%d\n”, ????);
fclose();
}
}
a) ftell( f )
b) fposition( f )
c) tell( f )
d) filelen( f )
ANSWER: A
14.Which of the following preprocessor directive will make the system- dependent constant INT_MAX available for ANSI C compiler?
a) #include <limits.h>
b) #include <int.h>
c) #include <ctype.h>
d) #define INT_MAX
ANSWER: A
15.After a library function returns a failure, which of the following will print out the appropriate error message corresponding to error number given by errno?
a) printf( stderr, “%s\n”, geterror () );
b) printer();
c) perror( errno).
d) strerror( errno).
ANSWER: D
16.Undefined functions calls in a c program are detected by
a) The preprocessor
b) The assembler
c) The linker
d) The operating system
ANSWER: C
17.What would be the output if the following program (myprog.c) is run using the following command line?
myprog jan feb mar apr
main( int size, char *arg[])
{
while( size ) printf(“%s”, arg[ --size ]);
}
a) myprog jan feb mar apr
b) apr mar feb jan myprog
c) jan feb mar apr
d) error
ANSWER: B
18.Study the following statement
#define DELAYTIME 1000
volatile extern int k;
int j;
for( i = 0; i < DELAYTIME; i++)
j = k;
state which of the following is true.
a) Volatile is meaningless for the variable k
b) Volatile is meaningful for the variable k since k is external and can change
c) Volatile is meaningless for the variable since k is loop variant
d) None
ANSWER: B
19.What is the output when the program is executed as prog arg 1?
Main ( int x, char *y[])
{
Printf(“%d %s”, x, y[1]);
}
a) 1 prog
b) 1 arg1
c) 2 prog
d) 2 arg1
ANSWER: D
20.The purpose of the following code is to find
#include <time.h>
main()
{
time_t t1, t2;
clock_t clock( void);
int I, x = 0, y = 10;
t1 = clock( );
for( I = 0; I < 10000; i++)
{
x++; y+ = 50;
printf(“the value of I = %d, x = %d, y = %d\n”, I, x, y);
}
t2 = clock( );
printf(“Time in seconds : %g\n”, difftime(t2, t1)/ CLOCKS_PER_SEC);
}
a) Compilation time
b) Execution time
c) Difference between GST and IST
d) Difference between compilation and execution time.
ANSWER: B
Very nice. Thanks for sharing these interview questions.
ReplyDeleteThank You very much for your feedback.
Delete