C_Programming_100_Questions
C_Programming_100_Questions
## Arrays
1. **Predict the output:**
```c
#include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40, 50};
printf("%d", arr[2]);
return 0;
}
```
**Answer:** 30
2. **What will happen if you try to access `arr[10]` for an array defined as `int
arr[5];`?**
**Answer:** Undefined behavior, as it exceeds the array bounds.
## Functions
51. **Predict the output:**
```c
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int main() {
printf("%d", add(5, 10));
return 0;
}
```
**Answer:** 15
52. **What is the difference between call by value and call by reference?**
**Answer:** Call by value copies the value of a variable into the function,
while call by reference passes the variable's address, allowing modification of the
original variable.
## Structures
76. **Define a structure `Student` and write a program to initialize and display
it.**
```c
#include <stdio.h>
struct Student {
char name[50];
int rollNo;
float marks;
};
int main() {
struct Student s1 = {"John Doe", 101, 85.5};
printf("Name: %s\nRoll No: %d\nMarks: %.2f", s1.name, s1.rollNo, s1.marks);
return 0;
}
```
**Answer:**
Name: John Doe
Roll No: 101
Marks: 85.50