Sample Questions

Output Tracing

#include <stdio.h>
int main() {
    int a = 10;
    
    printf("%d %d %d\n", a, a, a);       //10 10 10 //10
    printf("%d %d %d\n", a++, a++, a++); //12 11 10 //12
    printf("%d %d %d\n", ++a, ++a, ++a); //16 16 16 //16
    printf("%d %d %d\n", a++, ++a, a++); //18 19 16 //19
    printf("%d %d %d\n", ++a, a++, ++a); //22 20 22 //22
    
    return 0;
}
#include <stdio.h>
int main() {
    int a = 10;
    int *b = &a;
    
    printf("%d %d %d\n", a, a, a);       //10 10 10 //10
    printf("%d %d %d\n", a++, a++, a++); //12 11 10 //13
    printf("%d %d %d\n", ++a, ++a, ++a); //16 15 14 //16
    printf("%d %d %d\n", a++, ++a, a++); //18 18 16 //19
    printf("%d %d %d\n", ++a, a++, ++a); //22 20 20 //22
    
    return 0;
}
#include <stdio.h>
int main() {
    int a = 10;
    int *b = &a;
    int **c = &b;
    
    printf("%d %d %d\n", a, a, a);       //10 10 10 //10
    printf("%d %d %d\n", a++, a++, a++); //12 11 10 //13
    printf("%d %d %d\n", ++a, ++a, ++a); //16 15 14 //16
    printf("%d %d %d\n", a++, ++a, a++); //18 18 16 //19
    printf("%d %d %d\n", ++a, a++, ++a); //22 20 20 //22
    
    return 0;
}
#include <stdio.h>
int main() {
    int a = 10;
    int *b = &a;
    int **c = &b;
    
    printf("%d %d %d\n", a, *b, **c);//10 10 10 //10
    printf("%d %d %d\n", ++a, ++a, ++a);//13 12 11 //13
    printf("%d %d %d\n", ++a, ++(*b), ++(**c));//16 15 14 //16
    printf("%d %d %d\n", a++, (*b)++, (**c)++);//18 17 16 //19
    printf("%d %d %d\n", a++, ++(*b), (**c)++);//21 21 19 //22
    printf("%d %d %d\n", ++a, (*b)++, ++(**c));//25 23 23 //25
    
    return 0;
}
#include <stdio.h>
int main() {
    int a = 5, x = 0;
    
    a = 5;
    x = a++ + a++ + a++ + a++;
    printf("X = %d \tA=%d\n", x, a); //X = 26 	A=9
    
    a = 5;
    x = a++ + a++ - a++ + a++;
    printf("X = %d \tA=%d\n", x, a); //X = 12 	A=9
    
    a = 5;
    x = a++ + a++ * a++ + a++;
    printf("X = %d \tA=%d\n", x, a); //X = 55 	A=9
    
    a = 5;
    x = a++ + a++ - a++ * a++;
    printf("X = %d \tA=%d\n", x, a); //X = -45 	A=9
    
    a = 5;
    x = a++ + a++ * a++ * a++;
    printf("X = %d \tA=%d\n", x, a); //X = 341 	A=9

    return 0;
}
#include <stdio.h>
int main() {
    int a = 5, x = 0;
    
    a = 5;
    x = ++a + ++a + ++a + ++a;
    printf("X = %d \tA=%d\n", x, a); //X = 31 	A=9
    
    a = 5;
    x = ++a + ++a - ++a + ++a;
    printf("X = %d \tA=%d\n", x, a); //X = 15 	A=9
    
    a = 5;
    x = ++a + ++a * ++a + ++a;
    printf("X = %d \tA=%d\n", x, a); //X = 81 	A=9
    
    a = 5;
    x = ++a + ++a - ++a * ++a;
    printf("X = %d \tA=%d\n", x, a); //X = -67 	A=9
    
    a = 5;
    x = ++a + ++a * ++a * ++a;
    printf("X = %d \tA=%d\n", x, a); //X = 585 	A=9

    return 0;
}
#include <stdio.h>
int main() {
    int a = 5, x = 0;
    
    a = 5;
    x = a++ + ++a + a++ + ++a;
    printf("X = %d \tA=%d\n", x, a); //X = 28 	A=9
    
    a = 5;
    x = a++ + ++a - ++a + a++;
    printf("X = %d \tA=%d\n", x, a); //X = 12 	A=9
    
    a = 5;
    x = ++a + a++ * ++a + ++a;
    printf("X = %d \tA=%d\n", x, a); //X = 65 	A=9
    
    a = 5;
    x = ++a + a++ - a++ * ++a;
    printf("X = %d \tA=%d\n", x, a); //X = -50 	A=9
    
    a = 5;
    x = ++a + a++ * ++a * ++a;
    printf("X = %d \tA=%d\n", x, a); //X = 441 	A=9

    return 0;
}
#include <stdio.h>
int main() {
    int a = 10, b = 5;
    
    printf("%d\n", a || ++b);
    printf("%d\n", b);
    
    return 0;
}
#include <stdio.h>
int main() {
    int a = 100;
    char b = a*3;
    
    printf("%d\n", a);
    printf("%d\n", b);
    
    return 0;
}
#include<stdio.h>
int main()
{
    int a = 15, b = 4; // practice for 0 <= b <= 20
    printf("%d\n", a % b);
    printf("%d\n", a % -b);
    printf("%d\n", -a % b);
    printf("%d\n", -a % -b);
    
    return 0;
}
#include <iostream>
using namespace std;
int main() {
    string cars[4] = {"Apple", "Blueberry", "Banana", "Cherry", "Mango"}; 
    
    cout<<cars[3];
    cout<<cars[2];

    return 0;
}

Write C Programs for the following questions:

  • Write down a function that will check whether a year is a leap year or not

  • Write a program to calculate factorial

  • Write a pseudo code to identify whether a given sequence is palindrome or not using stack and queue. You do not need to write code to implement stack and queue.

  • Compute the sum of palindrome numbers between 100 and 999

  • Write a function to reverse a string without using a global variable

    • Write down a method in C++ to reverse a char array. You are not permitted to use temp array and STL lib function.

  • Find the number of integers not divisible by 3, 5, or 7 which are <= 100

  • Write a program using a pointer to insert a number in a sorted list, it was forbidden to use array notation like array[], all should be done by pointer notation.

  • Write a function that takes an integer number and separates each digit using recursion

Write pseudocode

  • Test whether a list is sorted or not

Last updated