C Files and Preprocessors - placement questions answers
1. Identify the token pasting operator?
a) +
b) ++
c) #
d) ##
View Answer / Hide Answer2. What is the value of CAR in the following Statement?
enum vehicle
{BUS, SCOOTER = 2, CAR, TRAIN = 5, AEROPLANE = 6}
a) 0
b) 1
c) 3
d) 4
View Answer / Hide Answer3. Given the following declaration identify the correct definition.
typedef struct node
{
int id;
char name[20];
};
a) node n;
b) NODE n;
c) typedef NODE n;
d) typedef node n;
View Answer / Hide Answer4. Identify the correct statement
1. The typedef defines synonym for an existing data type.
2. The typedef create a new data type that is not existing in C.
3. The typedef helps in easier modification of a portable program.
4. The typedef gives meaningful name to a data type.
a) Option 1, 3 and 4.
b) Option 1 and 4
c) Option 2 and 3
d) Option 2, 3 and 4
View Answer / Hide Answer5. What is the output of the following code?
enum control
{
On, off, neutral
};
PRINTF(“%d”, off);
a) Compilation error
b) Execution error
c) 5
d) 1
View Answer / Hide Answer6. What is the output of the following program?
#define MAX (x, y) ((x) > (y) ? (x) : (y))
main()
{
int x=5, y = 5;
printf(“maximum is %d”, MAX( ++x, ++y));
}
a) Maximum is 7
b) Maximum is 5
c) Maximum is 6
d) None
View Answer / Hide Answer7. Which ANSI C function can be used to obtain a date string from structure *tm?
a) sttime(tm)
b) asctime(tm)
c) gmtime(tm)
d) strtime(tm)
View Answer / Hide Answer8. given the statement x = fopen(b, c);
what is b?
a) Pointer to character array which contains the file name.
b) File name within double quotes
c) Option a or b
d) None
View Answer / Hide Answer9. What is the output generated by the following code?
#define square (a) (a * a)
printf(“%d”, square (4 + 5));
a) 81
b) 4
c) 29
d) None
View Answer / Hide Answer10. Which is more correct?
‘int main( int argc, char**argv)’
‘int main (int argc, char* argv[])’?
a) Both are equally wrong
b) Both are equally correct
c) Neither is correct
d) Int main(int argc, char** argv)
View Answer / Hide Answer11. Identify the trigraph sequence for ^.
a) ?? /
b) ?? =
c) ?? ’
d) ?? !
View Answer / Hide Answer12. void listFile(FILE *f)
{
int c;
While( c = fgetc( f ) != EOF)
{
printf(“%d”, c);
}
printf(“\n”);
}
What will be printed when the function above is called with pointer to a open file that contains the three characters abc?
a) The character ab followed by infinite no of c’s.
b) 1 1 1
c) a b c
d) 0 0 0
View Answer / Hide Answer13. void getFileLength( char *s)
{
FILE *f;
if( f = fopen( s, “r”) )
{
fseek(f, SEEK_SET, 2);
printf(“%d\n”, ????);
fclose();
}
}
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?
a) ftell( f )
b) fposition( f )
c) tell( f )
d) filelen( f )
View Answer / Hide Answer14. 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
View Answer / Hide Answer15. 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).
View Answer / Hide Answer16. Undefined functions calls in a c program are detected by
a) The preprocessor
b) The assembler
c) The linker
d) The operating system
View Answer / Hide Answer17. 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
View Answer / Hide Answer18. 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
View Answer / Hide Answer19. Main ( int x, char *y[])
{
Printf(“%d %s”, x, y[1]);
}
What is the output when the program is executed as prog arg 1?
a) 1 prog
b) 1 arg1
c) 2 prog
d) 2 arg1
View Answer / Hide Answer20. 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.
View Answer / Hide Answer21. If the function definition of a program are in a file metric.c , where are the prototype declarations likely to be?
a) metric.cpp
b) metric.i
c) metric.exe
d) metric.h
View Answer / Hide Answer22. Which of the following statements are correct?
a) A macro must always be defined in capital letters
b) Once preprocessing is over and the program is sent for the compilation the macros are removed from the expended source code
c) Macros have a local scope
d) In a macro call, the control is passed to the macro
View Answer / Hide Answer23. Which of the following statement is correct about the code snippet given below?
# include <stdio.h>
Int main()
{
FILE *fp;
char str[80];
fp = fopen(“ABC.C”, “r”);
while( fgets( str, 80, fp) != eof)
puts( str);
return 0;
}
a) The code reports an error as L-value required
b) Code gives an output as garbage value
c) Code reports an error as undefined symbol eof
d) The code reads the content of the file if it is present and displays it on the screen.
View Answer / Hide Answer24. What will be the output of the following code?
#include <stdio.h>
#define CUBE( Y) ( Y * Y * Y)
int main()
{
static int a, b = 3;
a = CUBE(++b)/b++;
printf(“a = %d b = %d”, a, b);
return 0;
}
a) a = 25 b = 7
b) a = 24 b = 7
c) a = 27 b = 6
d) a = 26 b = 9
View Answer / Hide Answer25. What is the use of #pragma directive?
a) Used for making program portable
b) Used for expression evaluation
c) Used to turn off and on certain features
d) Both A & B
View Answer / Hide Answer26. How will you define the macro AND and OR if the following C code snippet is to test whether a given character is alphabet or not?
#include <stdio.h>
#define LE <=
#define GE >=
int main()
{
char ch = ‘D’;
if(( ch GE 65 AND ch LE 90) OR (ch GE 97 AND ch LE 122))
printf(“Alphabet”);
else
printf(“Not an alphabet”);
return 0;
}
a) #define AND &&
#define OR ||
b) #define AND &
#define OR |
c) #define AND <
#define OR >
d) #define AND >>
#define OR <<
View Answer / Hide Answer27. void testit( struct cust_rec *sptr, char *s)
{……..; }
Referring to the sample code above, if a calling function has a char array variable string length 10 and a cust_rec structure variable record, what would be the correct call to testit?
a) testit( &record, *string)
b) testit( &record, string)
c) testit( &record, &string)
d) testit( record, *string)
View Answer / Hide Answer28. Stream oriented files are accessed through
a) System calls
b) Library functions
c) Linker
d) Loader
View Answer / Hide Answer29. The function ftell( fptr) returns
a) The beginning position of the file represented by fptr
b) The end position of the file represented by fptr
c) The current position of the file represented by fptr
d) The middle position of the file represented by fptr
View Answer / Hide Answer30. Identify the stringizing operator.
a) +
b) ::
c) #
d) ##
View Answer / Hide Answer