shortQ&A.ctp
shortQ&A.ctp
1. *What is C programming?*
- C is a high-level programming language that was developed in the 1970s. It is widely used for system programming,
developing operating systems, and embedded systems due to its performance and control over system resources.
4. *What is a pointer?*
- The printf() function is used to output/display information to the standard output (usually the screen).
- ++i is a pre-increment operation (increments first, then uses the value), while i++ is a post-increment operation (uses
the current value first, then increments).
- A function is a block of code that performs a specific task, and can be called upon to execute from other parts of the
program.
9. *What is recursion?*
- An array is a collection of elements of the same data type stored in contiguous memory locations.
- A structure is a user-defined data type in C that allows grouping different data types together.
- A union is a data structure similar to a structure, but it can store only one member's value at a time because all
members share the same memory location.
- In a struct, all members have separate memory locations, while in a union, all members share the same memory
location.
- Header files contain function declarations and macros and are included in the program using the #include directive.
- A macro is a fragment of code that has been given a name. It is defined using #define and can be reused throughout
the program.
17. **What is the difference between #include <filename> and #include "filename"?**
- #include <filename> is used for system header files, while #include "filename" is used for user-defined header files.
18. *What is a file pointer in C?*
- A file pointer is a pointer to a file structure, and it is used to work with files in C. It is declared as FILE *fp.
- malloc() allocates a single block of memory, while calloc() allocates multiple blocks and initializes them to zero.
- Dynamic memory allocation allows memory to be allocated during runtime using functions like malloc(), calloc(),
realloc(), and free().
- A dangling pointer is a pointer that points to memory that has been freed or deleted.
- A segmentation fault occurs when a program tries to access memory that it is not allowed to, such as dereferencing a
null or invalid pointer.
- The four storage classes in C are auto, static, extern, and register.
- auto variables have local scope and are destroyed after function execution. static variables retain their value across
function calls and have a global lifetime.
- Scope refers to the region of the program where a variable can be accessed.
- The return statement terminates the execution of a function and returns a value to the calling function.
- break exits a loop entirely, while continue skips the current iteration and moves to the next iteration of the loop.
- An infinite loop is a loop that continues to execute without a terminating condition, such as while(1).
- Inline functions are small functions whose code is inserted directly into the calling code to reduce function call
overhead.
- A for loop is used when the number of iterations is known beforehand, while a while loop is used when the number
of iterations is not known.
- The conditional operator (?:) is a shorthand for an if-else statement, used to evaluate a condition and return one of
two values.
- A pointer to a function stores the address of a function, allowing the function to be called indirectly.
- Preprocessor directives are instructions processed before the actual compilation starts. Examples include #include,
#define, and #if.
35. *What is an enumerated type in C?*
- An enumerated type (enum) is a user-defined data type consisting of named integer constants.
- sizeof is a compile-time operator that returns the size, in bytes, of a data type or variable.
- Bitwise operators operate on bits and include &, |, ^, ~, <<, and >>.
- Command-line arguments are passed to the program at runtime through the command line and are accessed via
argc (argument count) and argv (argument vector).
- exit() terminates the entire program, while return only exits the current function.
- volatile tells the compiler that the value of a variable may change unexpectedly and should not be optimized.
- The const keyword is used to declare variables whose values cannot be changed after initialization.
- The extern keyword is used to declare a variable that is defined in another file or a function that will be linked at
runtime.
- Wild pointers are pointers that have not been initialized and point to arbitrary memory locations.
44. **What is the purpose of the NULL pointer?**
- A NULL pointer is used to indicate that a pointer does not point to any valid memory location.
- A NULL pointer is a pointer that points to nothing, while a void pointer is a generic pointer that can point to any data
type.
- Type qualifiers, such as const, volatile, and restrict, provide additional information about variables, like their
mutability or how they are accessed.
- An lvalue refers to a memory location that can appear on the left-hand side of an assignment, while an rvalue is a
data value that can appear on the right-hand side.
- Formatted I/O functions like printf() and scanf() allow input/output with specific formatting. Unformatted I/O
functions like getchar() and putchar() handle input/output of raw data without formatting.
- memcpy() copies memory between non-overlapping areas, while memmove() safely copies memory between
potentially overlapping areas.
- The free() function is used to deallocate memory that was dynamically allocated using malloc() or calloc().