0% found this document useful (0 votes)
6 views4 pages

Unit 4

This document contains a series of questions and answers related to programming in C, covering topics such as directives, variable declaration, library functions, user-defined functions, recursion, structures, pointers, and file handling. Each question is followed by the correct answer, providing a concise overview of fundamental C programming concepts. It serves as a study guide for understanding key elements of the C programming language.

Uploaded by

ybimala17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Unit 4

This document contains a series of questions and answers related to programming in C, covering topics such as directives, variable declaration, library functions, user-defined functions, recursion, structures, pointers, and file handling. Each question is followed by the correct answer, providing a concise overview of fundamental C programming concepts. It serves as a study guide for understanding key elements of the C programming language.

Uploaded by

ybimala17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Unit- 4

Programming in C
1. What does the #include directive do in a C program?
a) Declares variables
b) Defines constants
c) Includes header files
d) Compiles the program

Answer: c

2. What is the correct syntax to declare an integer variable in C?


a) int var;
b) var int;
c) integer var;
d) int = var;

Answer: a

3. What is a library function in C?


a) A user-defined function
b) A function pre-defined in C libraries
c) A function without parameters
d) A function written in assembly language

Answer: b

4. Which keyword is used to define a function in C?


a) function
b) def
c) No specific keyword
d) void

Answer: c

5. What is the advantage of user-defined functions?


a) Improves code reusability
b) Reduces compilation time
c) Limits memory usage
d) Removes the need for libraries

Answer: a

6. What does a function prototype provide in C?


a) Function implementation
b) Return type and parameter details
c) Variable declarations
d) Memory allocation

Answer: b

7. Which keyword is used to return a value from a function?


a) return
b) exit
c) output
d) end

Answer: a

8. What is "call by value"?


a) Passing the memory address of variables
b) Passing a copy of the variable's value
c) Calling the function without arguments
d) Returning multiple values

Answer: b

9. Which storage class has a lifetime limited to the block in which it is declared?
a) automatic
b) static
c) external
d) register

Answer: a

10. What is the default storage class for variables in C?


a) auto
b) static
c) extern
d) register

Answer: a

11. Which problem is typically solved using recursion?


a) Sorting
b) Fibonacci series
c) Matrix multiplication
d) File handling

Answer: b

12. What is the base case in recursion?


a) The recursive function call
b) The stopping condition
c) The condition for infinite recursion
d) The last line of code

Answer: b

13. How do you access a structure member?


a) ->
b) .
c) &
d) *

Answer: b

14. What is the main difference between a structure and a union?


a) Structures use pointers; unions do not
b) Structures allocate separate memory for each member, unions share memory
c) Structures cannot contain arrays, unions can
d) Structures are faster than unions

Answer: b

15. What does the indirection operator (*) do in C?


a) Access the address of a variable
b) Access the value stored at a memory location
c) Perform multiplication
d) Create a pointer

Answer: b

16. Which of the following is true about pointer assignment?


a) A pointer can point to any data type
b) A pointer must point to the same data type
c) Pointers are always initialized to NULL
d) Pointers cannot be reassigned

Answer: b

17. Which file function is used to write an integer to a file?


a) putw
b) getw
c) putc
d) fwrite

Answer: a

18. What does the fscanf function do?


a) Writes formatted output to a file
b) Reads formatted input from a file
c) Reads a single character from a file
d) Appends data to a file

Answer: b

19. What is the default mode of opening a file using fopen in C?


a) Write mode
b) Read mode
c) Append mode
d) Binary mode

Answer: b

20. In random file access, which function moves the file pointer to a specific location?
a) fseek
b) ftell
c) rewind
d) fwrite

Answer: a

You might also like