C_Language_QnA (1)
C_Language_QnA (1)
1. What is Preprocessor?
A preprocessor in C is a tool that processes the source code before it is compiled. It handles directives like
A structure in C is a user-defined data type that groups variables of different types under one name.
Syntax:
struct StructureName {
data_type member1;
data_type member2;
};
Accessing Members:
Use the dot operator (.) for direct access or the arrow operator (->) if accessing via a pointer.
3. What is a file? What are the various modes of files available in C Language?
Modes:
- r (read)
- w (write)
- a (append)
- rb, wb, ab (binary modes)
int x = 10;
int *p = &x;
Example:
int x = 10;
Example:
struct Node {
int data;
};
An array is a collection of elements of the same data type stored at contiguous memory locations.
Applications:
- Matrix operations.
11. Which one takes less memory, structure or union? And why?
A union takes less memory because it allocates memory equal to the size of its largest member, while a str
Syntax:
data_type array_name[size1][size2][size3];
Example:
int arr[2][3][4];
#include<stdio.h>
arr[j + 1] = temp;
}
}
int main() {
int n = sizeof(arr)/sizeof(arr[0]);
bubbleSort(arr, n);
return 0;
#include<stdio.h>
while (*source) {
*destination = *source;
source++;
destination++;
*destination = '\0';
int main() {
char destination[20];
stringCopy(source, destination);
printf("Copied String: %s", destination);
return 0;
Definition:
struct StructureName {
data_type member1;
data_type member2;
};
Declaration:
#include<stdio.h>
int main() {
fputc(ch, file3);
fputc(ch, file3);
fclose(file1);
fclose(file2);
fclose(file3);
return 0;