Which standard library function in C is used to concatenate two strings?
- strcat
- strcmp
- strconcat
- strcopy
The strcat function in C is used to concatenate (append) one string to the end of another. It takes two strings as arguments and modifies the first string to include the second one at the end.
The use of ________ allows for dynamic memory allocation for arrays in C.
- for loop
- getchar()
- malloc()
- sizeof()
Dynamic memory allocation in C is achieved using functions like malloc().
What is the standard notation for passing command line arguments in a C program?
- int main(String[] args)
- int main(int argc, char *argv[])
- main(int argc, char *argv[])
- void main(args)
The standard notation for passing command line arguments in a C program is 'int main(int argc, char *argv[])'. 'argc' holds the number of arguments, and 'argv' is an array of argument values.
The ________ statement is used to exit a loop prematurely.
- break
- continue
- return
- switch
In programming, the "break" statement is used to exit a loop prematurely. It is often used in loops such as "for" and "while" to terminate the loop based on a specific condition. The "break" statement is not used to return from a function, control a switch statement, or skip the current iteration of a loop, so it is the correct option.
When declaring a pointer in C, which symbol is used to denote that a variable is a pointer?
- #
- $
- &
- *
In C, the asterisk (*) symbol is used to declare a pointer variable. For example, int *ptr declares a pointer to an integer.
When you increment a pointer in C, it advances the pointer by the size of the type to which it points, which is known as ________.
- Looping
- Memory allocation
- Pointer arithmetic
- Typecasting
When you increment a pointer in C, it advances the pointer by the size of the type to which it points, and this operation is known as pointer arithmetic. It allows you to navigate through data structures in memory.
What is the significance of using pointers when working with structures in C?
- Pointers allow dynamic memory allocation.
- Pointers enable structures to be passed to functions efficiently.
- Pointers prevent data corruption in structures.
- Pointers simplify access to structure members.
Using pointers when working with structures in C is essential because they enable efficient access to structure members when they are passed to functions. This allows you to manipulate data inside structures without having to create copies of the entire structure.
How can a structure be passed to a function in C?
- By creating a copy inside the function
- By reference
- By using global variables
- By value
A structure can be passed to a function in C by reference (using a pointer or passing the address of the structure). This allows the function to modify the original structure's contents.
What is a pointer in C programming?
- A control structure in C
- A data type used for characters
- A function that returns values
- A variable that stores addresses
A pointer in C is a variable that stores the memory address of another variable. It's often used for dynamic memory allocation and accessing data indirectly.
What is the role of the 'continue' statement in a loop?
- It exits the program.
- It restarts the loop from the beginning.
- It skips the current iteration and continues with the next.
- It terminates the loop.
The 'continue' statement is used in loops to skip the current iteration and move to the next iteration. It does not terminate the loop but helps to skip certain iterations.