0% found this document useful (0 votes)
5 views

C aptitude and recursion-based ques

The document contains a series of C programming questions focused on various topics such as recursion, pointer arithmetic, array manipulation, string handling, and more. Each question is accompanied by a code snippet and asks for the expected output. The document serves as a practice resource for understanding fundamental C programming concepts.

Uploaded by

Guru Ashwin
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

C aptitude and recursion-based ques

The document contains a series of C programming questions focused on various topics such as recursion, pointer arithmetic, array manipulation, string handling, and more. Each question is accompanied by a code snippet and asks for the expected output. The document serves as a practice resource for understanding fundamental C programming concepts.

Uploaded by

Guru Ashwin
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

C aptitude and recursion-based questions---

### 1. Recursion: Factorial Calculation


```c
#include <stdio.h>
int fact(int n) {
if (n <= 1) return 1;
return n * fact(n - 1);
}
void main() {
int n = 5;
printf("%d", fact(n));
}
```
Output?

---

### 2. Pointer Arithmetic


```c
#include <stdio.h>
void main() {
int arr[] = {10, 20, 30, 40};
int *ptr = arr;
ptr++;
printf("%d", *ptr);
}
```
Output?

---

### 3. Logical Bit Shift


```c
#include <stdio.h>
void main() {
int x = 10;
printf("%d", x >> 1);
}
```
Output?

---

### 4. Array Manipulation


```c
#include <stdio.h>
void main() {
int arr[] = {1, 2, 3, 4, 5};
for (int i = 0; i < 5; i++)
printf("%d ", arr[i]);
}
```
Output?

---

### 5. String Handling


```c
#include <stdio.h>
#include <string.h>
void main() {
char str[] = "Zoho";
str[1] = '\0';
printf("%s", str);
}
```
Output?

---

### 6. Recursion: Fibonacci Sequence


```c
#include <stdio.h>
int fib(int n) {
if (n <= 1) return n;
return fib(n - 1) + fib(n - 2);
}
void main() {
printf("%d", fib(5));
}
```
Output?

---

### 7. Pointer Dereferencing


```c
#include <stdio.h>
void main() {
int x = 10;
int *p = &x;
printf("%d", *p);
}
```
Output?

---

### 8. Multi-Dimensional Array


```c
#include <stdio.h>
void main() {
int arr[2][2] = {{1, 2}, {3, 4}};
printf("%d", arr[1][0]);
}
```
Output?

---

### 9. Recursive Summation


```c
#include <stdio.h>
int sum(int n) {
if (n == 0) return 0;
return n + sum(n - 1);
}
void main() {
printf("%d", sum(5));
}
```
Output?

---

### 10. Floating Point Arithmetic


```c
#include <stdio.h>
void main() {
float x = 5.0 / 2;
printf("%.1f", x);
}
```
Output?

---

### 11. Bit Manipulation


```c
#include <stdio.h>
void main() {
int x = 5;
x = x | 2;
printf("%d", x);
}
```
Output?

---

### 12. Function Pointers


```c
#include <stdio.h>
void greet() {
printf("Hello World\n");
}
void main() {
void (*func_ptr)() = greet;
func_ptr();
}
```
Output?

---

### 13. String Length


```c
#include <stdio.h>
#include <string.h>
void main() {
char str[] = "ZohoTest";
printf("%lu", strlen(str));
}
```
Output?
---

### 14. Integer Division


```c
#include <stdio.h>
void main() {
int x = 7 / 2;
printf("%d", x);
}
```
Output?

---

### 15. Conditional Statements


```c
#include <stdio.h>
void main() {
int x = 10;
if (x > 5)
printf("Greater");
else
printf("Smaller");
}
```
Output?

---

### 16. Recursion: Binomial Coefficient


```c
#include <stdio.h>
int binomialCoeff(int n, int k) {
if (k == 0 || k == n) return 1;
return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k);
}
void main() {
printf("%d", binomialCoeff(5, 2));
}
```
Output?

---

### 17. Structure and Pointers


```c
#include <stdio.h>
struct Point {
int x, y;
};
void main() {
struct Point p1 = {10, 20};
struct Point *p = &p1;
printf("%d %d", p->x, p->y);
}
```
Output?

---
### 18. Logical Operations
```c
#include <stdio.h>
void main() {
int x = 1, y = 0;
printf("%d", x && y);
}
```
Output?

---

### 19. Memory Allocation


```c
#include <stdio.h>
#include <stdlib.h>
void main() {
int *ptr = (int *)malloc(4 * sizeof(int));
for (int i = 0; i < 4; i++)
ptr[i] = i;
printf("%d", ptr[2]);
free(ptr);
}
```
Output?

---

### 20. Hexadecimal Representation


```c
#include <stdio.h>
void main() {
printf("%x", 255);
}
```
Output?

---

(And 10 more questions similar to these topics).

You might also like