Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NETUncategorized

C Programming Questions and Answers – File Inclusion

C Programming Questions and Answers – File Inclusion

 

1.What is the sequence for preprocessor to look for the file within <> ?

a) The predefined location then the current directory

b) The current directory then the predefined location

c) The predefined location only

d) The current directory location

View Answer

Answer:a

Explanation:<> first searches the predefined location for the specified file and then the current director.

 

2.Which directory the compiler first looks for the file when using #include ?

a) Current directory where program is saved

b) C:COMPILERINCLUDE

c) S:SOURCEHEADERS

d) Both (b) and (c) simultaneously

View Answer

Answer:b

Explanation:The order of file look up is in the sequence of option b, c, a.

 

3.What would happen if you create a file stdio.h and use #include “stdio.h” ?

a) The predefined library file will be selected

b) The user-defined library file will be selected

c) Both the files will be included

d) The compiler won’t accept the program

View Answer

Answer:b

 

 

4.How is search done in #include and #include “somelibrary.h” according to C standard?

a) When former is used, current directory is searched and when latter is used, standard directory is searched

b) When former is used, standard directory is searched and when latter is used, current directory is searched

c) When former is used, search is done in implementation defined manner and when latter is used, current directory is searched

d) For both, search for ‘somelibrary’ is done in implementation-defined places

View Answer

Answer:d

 

 

5.How is search done in #include and #include”somelibrary.h” normally or conventionally?

a) When former is used, current directory is searched and when latter is used, standard directory is searched

b) When former is used, predefined directory is searched and when latter is used, current directory is searched and then predefined directories are searched

c) When former is used, search is done in implementation defined manner and latter is used to search current directory

d) For both, search for somelibrary is done in implementation-defined manner

View Answer

Answer:b

 

6.Can function definition be present in header files?

a) Yes

b) No

c) Depends on the compiler

d) Depends on the standard

View Answer

Answer:a

 

 

7.Comment on the output of this C code?

 

#include <stdio.h>

#include “test.h”

#include “test.h”

int main()

{

//some code

}

a) true

b) Compile time error

c) false

d) Depends on the compiler

View Answer

Answer:b

 

 

8.What is the output of this C code?

 

#include <stdio.h>

#define foo(m, n) m ## n

void myfunc();

int main()

{

myfunc();

}

void myfunc()

{

printf(“%d\n”, foo(2, 3));

}

a) 23

b) 2 3

c) Compile time error

d) Undefined behaviour

View Answer

Answer:a

 

9.If the file name is enclosed in double quotation marks

a) The preprocessor treats it as a user-defined file

b) The preprocessor treats it as a system-defined file

c) Both a & b

d) None of the mentioned

View Answer

Answer:a

 

10.If the file name is enclosed in angle brackets

a) The preprocessor treats it as a user-defined file

b) The preprocessor treats it as a system-defined file

c) Both a & b

d) None of the mentioned

View Answer

Answer:b

 

11.What is the output of this C code?

 

#include (stdio.h)

void main()

{

printf(“hello”);

}

a) hello

b) Nothing

c) compile time error

d) Depends on compiler

View Answer

Answer:c

Explanation:File to be included must be specified either in “” or <>.

Output:

$ cc pgm1.c

pgm1.c:1: error: #include expects “FILENAME” or

pgm1.c: In function ‘main’:

pgm1.c:4: warning: incompatible implicit declaration of built-in function ‘printf’

 

12.The below two lines are equivalent to

#define C_IO_HEADER

#include C_IO_HEADER

a) #include

b) #include”printf”

c) #include”C_IO_HEADER”

d) #include

View Answer

Answer:d

Explanation:Since C_IO_HEADER is defined to be , the second line becomes #include, since C_IO_HEADER is replaced with

 

13.What is the output of this C code?

 

#include <stdio.h>

#include “printf”

void main()

{

printf(“hello”);

}

a) hello

b) Error

c) Depends on compiler

d) Varies

View Answer

Answer:a

 

14.Which of the following file extensions are accepted with #include?

a) .h

b) .in

c) .com

d) All of the mentioned

View Answer

Answer:d

Explanation:The preprocessor will include whatever file extension you specify in your #include statement. However, it is not a good practice as another person debugging it will find it difficulty in finding files you have included.

 

15.Which of the following names for files not accepted?

a) header.h.h

b) 123header.h

c) _head_er.h

d) None of the mentioned

View Answer

Answer:d

Explanation:All file names are accepted as for the execution to occur. There are no constraints on giving file names for inclusion.

Related Articles

Leave a Reply

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

Check Also
Close
Back to top button