### 30 C Programming Aptitude Questions
---
#### **1. Operators**
```c
#include <stdio.h>
int main() {
int a = 5, b = 10, c = 15;
printf("%d", a < b < c);
return 0;
}
```
---
#### **2. Precedence**
```c
#include <stdio.h>
int main() {
int x = 10;
printf("%d", x++ * ++x);
return 0;
}
```
---
#### **3. Memory Size**
```c
#include <stdio.h>
int main() {
char str[] = "Zoho";
printf("%lu", sizeof(str));
return 0;
}
```
---
#### **4. Conditional Operator**
```c
#include <stdio.h>
int main() {
int a = 5, b = 10;
printf("%d", a > b ? a : b);
return 0;
}
```
---
#### **5. Type Casting**
```c
#include <stdio.h>
int main() {
int x = 97;
printf("%c", (char)x);
return 0;
}
```
---
#### **6. String Manipulation**
```c
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello";
printf("%ld", strlen(str));
return 0;
}
```
---
#### **7. Pointers**
```c
#include <stdio.h>
int main() {
int x = 10;
int *p = &x;
printf("%d", *p + 1);
return 0;
}
```
---
#### **8. Pointer Arithmetic**
```c
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4};
printf("%d", *(arr + 2));
return 0;
}
```
---
#### **9. Array**
```c
#include <stdio.h>
int main() {
int arr[] = {5, 10, 15, 20};
printf("%d", arr[2]);
return 0;
}
```
---
#### **10. Logical Operators**
```c
#include <stdio.h>
int main() {
int a = 5, b = 0;
printf("%d", a && b);
return 0;
}
```
---
#### **11. Bitwise Operators**
```c
#include <stdio.h>
int main() {
int a = 5;
printf("%d", a & 1);
return 0;
}
```
---
#### **12. Bit Shifting**
```c
#include <stdio.h>
int main() {
int a = 8;
printf("%d", a >> 2);
return 0;
}
```
---
#### **13. Function**
```c
#include <stdio.h>
int square(int x) {
return x * x;
}
int main() {
printf("%d", square(5));
return 0;
}
```
---
#### **14. Static Variable**
```c
#include <stdio.h>
void fun() {
static int x = 0;
x++;
printf("%d", x);
}
int main() {
fun();
fun();
return 0;
}
```
---
#### **15. Recursion**
```c
#include <stdio.h>
int fact(int n) {
return (n == 0) ? 1 : n * fact(n - 1);
}
int main() {
printf("%d", fact(4));
return 0;
}
```
---
#### **16. Pointer to Pointer**
```c
#include <stdio.h>
int main() {
int x = 10;
int *p = &x;
int **q = &p;
printf("%d", **q);
return 0;
}
```
---
#### **17. Structures**
```c
#include <stdio.h>
struct Point {
int x, y;
};
int main() {
struct Point p = {5, 10};
printf("%d %d", p.x, p.y);
return 0;
}
```
---
#### **18. Unions**
```c
#include <stdio.h>
union Data {
int i;
float f;
};
int main() {
union Data d;
d.i = 10;
printf("%d", d.i);
return 0;
}
```
---
#### **19. Dynamic Memory**
```c
#include <stdio.h>
#include <stdlib.h>
int main() {
int *p = (int *)malloc(sizeof(int));
*p = 5;
printf("%d", *p);
free(p);
return 0;
}
```
---
#### **20. Strings**
```c
#include <stdio.h>
int main() {
char str[] = "Zoho";
printf("%c", str[2]);
return 0;
}
```
---
#### **21. Typedef**
```c
#include <stdio.h>
typedef unsigned int uint;
int main() {
uint x = 5;
printf("%u", x);
return 0;
}
```
---
#### **22. Macros**
```c
#include <stdio.h>
#define SQUARE(x) x * x
int main() {
printf("%d", SQUARE(4));
return 0;
}
```
---
#### **23. Nested Loops**
```c
#include <stdio.h>
int main() {
int i, j;
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
printf("%d%d ", i, j);
}
}
return 0;
}
```
---
#### **24. Command Line Arguments**
```c
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("%d", argc);
return 0;
}
```
---
#### **25. Infinite Loop**
```c
#include <stdio.h>
int main() {
while (1) {
printf("Hello");
break;
}
return 0;
}
```
---
#### **26. Do While**
```c
#include <stdio.h>
int main() {
int x = 0;
do {
printf("%d", x++);
} while (x < 3);
return 0;
}
```
---
#### **27. Float Precision**
```c
#include <stdio.h>
int main() {
float f = 3.14;
printf("%.2f", f);
return 0;
}
```
---
#### **28. Array of Pointers**
```c
#include <stdio.h>
int main() {
char *arr[] = {"Hello", "World"};
printf("%s", arr[1]);
return 0;
}
```
---
#### **29. Enum**
```c
#include <stdio.h>
enum Days {Mon, Tue, Wed};
int main() {
printf("%d", Wed);
return 0;
}
```
---
#### **30. File I/O**
```c
#include <stdio.h>
int main() {
FILE *fp = fopen("test.txt", "w");
fprintf(fp, "Hello");
fclose(fp);
return 0;
}
```