Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Find output of C programs Questions with Answers Set 01

Program 1:

#include <stdio.h>

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    int *ptr = &arr[0];
    printf("%d\n", *++ptr);
    printf("%d\n", *(ptr++));
    return 0;
}
View output

2
3


Program 2:

#include <stdio.h>

int main() {
    int i = 0;
    for (; i < 5; i++) {
        if (i == 2)
            continue;
        printf("%d ", i);
    }
    return 0;
}
View output

0 1 3 4


Program 03:

#include <stdio.h>

int main() {
    int x = 5;
    int *ptr = &x;
    printf("%d %p\n", *ptr, ptr);
    (*ptr)++;
    printf("%d\n", x);
    return 0;
}
View output

5 address of x
6


Program 04:

#include <stdio.h>

int main() {
    int x = 10;
    int *ptr1 = &x, *ptr2 = &x;
    (*ptr1)++;
    printf("%d %d\n", *ptr1, *ptr2);
    return 0;
}
View output

11 11


Program 05:

#include <stdio.h>

int main() {
    char str[] = "Hello, World!";
    char *ptr = str;
    printf("%c\n", *ptr++);
    printf("%s\n", ptr);
    return 0;
}
View output

H
ello, World!


Program 06:

#include <stdio.h>

int main() {
    int x = 5;
    printf("%d\n", x++);
    printf("%d\n", ++x);
    return 0;
}
View output

5
7


Program 07:

#include <stdio.h>

int main() {
    int a = 10, b = 20;
    printf("%d\n", a++ + b++);
    printf("%d %d\n", a, b);
    return 0;
}
View output

30
11 21


Program 08:

#include <stdio.h>

int main() {
    int i = 10;
    while (i++ <= 15) {
        printf("%d ", i);
    }
    return 0;
}
View output

11 12 13 14 15 16


Program 09:

#include <stdio.h>

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    int *ptr = arr;
    printf("%d\n", *ptr++);
    printf("%d\n", *ptr);
    return 0;
}
View output

1
2


Program 10:

#include <stdio.h>

int main() {
    int x = 10, y = 20;
    int *ptr1 = &x, *ptr2 = &y;
    printf("%d %d\n", *ptr1, *ptr2);
    ptr1 = ptr2;
    printf("%d %d\n", *ptr1, *ptr2);
    return 0;
}
View output

10 20
20 20


Program 11:

#include <stdio.h>

void func(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

int main() {
    int x = 10, y = 20;
    printf("Before swapping: x = %d, y = %d\n", x, y);
    func(&x, &y);
    printf("After swapping: x = %d, y = %d\n", x, y);
    return 0;
}
View output

Before swapping: x = 10, y = 20
After swapping: x = 20, y = 10


Program 12:

#include <stdio.h>

int main() {
    char *str = "Hello";
    printf("%c\n", *str);
    printf("%s\n", str);
    return 0;
}
View output

H
Hello


Program 13:

#include <stdio.h>

int main() {
    int a = 10;
    int *ptr = &a;
    printf("%d\n", *ptr);
    *ptr = 20;
    printf("%d\n", a);
    return 0;
}
View output

10
20


Program 14:

#include <stdio.h>

int main() {
    int x = 10, y = 20;
    int *ptr1 = &x, *ptr2 = &y;
    *ptr1 += *ptr2;
    printf("%d\n", x);
    return 0;
}
View output

30


Program 15:

#include <stdio.h>

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    printf("%d\n", *arr + 3);
    return 0;
}
View output

4


Program 16:

#include <stdio.h>

void swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

int main() {
    int x = 5, y = 10;
    swap(&x, &y);
    printf("x = %d, y = %d\n", x, y);
    return 0;
}
View output

x = 10, y = 5


Program 17:

#include <stdio.h>

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    int *ptr = arr;
    printf("%d\n", *ptr++);
    printf("%d\n", *ptr);
    return 0;
}
View output

1
2


Program 18:

#include <stdio.h>

int main() {
    int i = 0;
    while (i < 5) {
        printf("%d ", ++i);
    }
    return 0;
}
View output

1 2 3 4 5


Program 19:

#include <stdio.h>

int main() {
    char str[] = "Hello";
    char *ptr = str;
    printf("%c\n", *(ptr + 1));
    printf("%s\n", ptr + 2);
    return 0;
}
View output

e
llo


Program 20:

#include <stdio.h>

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    printf("%d\n", *arr + 2);
    return 0;
}
View output

3


Program 21:

#include <stdio.h>

int main() {
    int arr[] = {10, 20, 30, 40, 50};
    int *ptr = arr;
    printf("%d\n", *ptr++);
    printf("%d\n", *++ptr);
    return 0;
}
View output

10
30


Program 22:

#include <stdio.h>

int main() {
    int x = 10, y = 5;
    int *ptr1 = &x, *ptr2 = &y;
    *ptr1 = *ptr1 + *ptr2;
    printf("%d\n", x);
    return 0;
}
View output

15