Certainly! Here are 10 short questions along with their answers on programming in C:
- Question: What is the purpose of the
#include <stdio.h>directive in C?
Answer: The#include <stdio.h>directive is used to include the standard input-output library in C, which provides functions likeprintf()andscanf()for input and output operations. - Question: Explain the difference between
printf()andscanf()functions in C.
Answer:printf()is used for formatted output, allowing you to display data on the screen, whilescanf()is used for formatted input, allowing you to read data from the user or a file. - Question: What is the significance of the
main()function in a C program?
Answer: Themain()function serves as the entry point of a C program. It is where the execution of the program begins and ends. Every C program must have exactly onemain()function. - Question: How are comments written in C? Provide examples.
Answer: Comments in C can be written using//for single-line comments or/* */for multi-line comments. For example:
// This is a single-line comment /* This is a multi-line comment */
- Question: What is the purpose of the
sizeofoperator in C?
Answer: Thesizeofoperator is used to determine the size of a variable or data type in bytes. It helps in writing portable code by providing a way to calculate the memory requirements of variables. - Question: How do you declare a constant in C?
Answer: Constants in C can be declared using theconstkeyword. For example:
const int MAX_VALUE = 100;
- Question: Explain the difference between
++iandi++in C.
Answer: Both++iandi++increment the value ofiby 1. However,++iis the pre-increment operator, which incrementsiand then returns the incremented value, whilei++is the post-increment operator, which returns the current value ofiand then increments it. - Question: What is a pointer in C?
Answer: A pointer in C is a variable that stores the memory address of another variable. It allows direct manipulation of memory and enables dynamic memory allocation and efficient access to data structures. - Question: How do you dynamically allocate memory in C?
Answer: Memory can be dynamically allocated in C using functions likemalloc(),calloc(), andrealloc(), which allocate memory on the heap at runtime and return a pointer to the allocated memory. - Question: What is the purpose of the
returnstatement in a function?
Answer: Thereturnstatement is used to exit a function and return a value to the caller. It can also be used to return control to the caller before the end of the function body.

