Why is an escape sequence used? Explain with examples.

An escape sequence is used to represent special characters that cannot be typed directly, such as newline, tab, or quotes. For example, \n represents a newline, \t represents a tab space, and \” represents a double quote. Example: printf(“Hello\nWorld”); This will print “Hello” on one line and “World” on the next. Related Questions: Why is … Read more

Why is a format specifier used? Explain with examples.

A format specifier is used to specify the type of data that should be displayed or processed when using input/output functions like printf() and scanf(). It ensures proper formatting of values. For example, %d is used for integers, %f for floating-point numbers, and %s for strings. Example: int num = 10; printf(“The number is %d”, … Read more

What is dynamic memory allocation in C? Explain malloc(), calloc(), and free() functions with examples.

Dynamic memory allocation allows programs to allocate memory at runtime, enabling flexibility in managing memory. This is achieved through functions like malloc(), calloc(), and free(). malloc(): The malloc() function allocates a block of memory of a specified size and returns a pointer to it. The memory is not initialized. int *ptr = (int *)malloc(5 * … Read more

Describe the concept of functions in C and explain different types of functions.

In C, a function is a self-contained block of code that performs a specific task. Functions are used to break down a program into smaller, reusable sections, making the code more organized and modular. The function is defined by its name, return type, parameters, and body. Functions in C can be categorized into two types: … Read more

What are the different types of storage classes in C?

In C, storage classes define the scope, lifetime, and visibility of variables. The main types are: auto: Default for local variables, their scope is limited to the block in which they are declared. register: Used for variables that should be stored in a register rather than RAM for faster access. static: Preserves the value of … Read more