C Operators Practice Questions with Solutions

Operators are one of the most important concepts in C programming. They are used to perform operations on variables and values, such as addition, subtraction, comparison, and logical evaluation. Understanding operators is essential for solving programming problems, building applications, and preparing for coding interviews.

In this chapter, you’ll practice beginner-friendly C operator programs. Each question includes a complete solution, sample output, explanation, and concepts covered. C Operators practice questions with solutions help to understand the concepts.


1. C Program to Add Two Numbers

Problem Statement

Write a C program to add two integers and display the result.

C Solution

#include <stdio.h>

int main()
{
    int first = 25;
    int second = 15;

    int sum = first + second;

    printf("Sum = %d", sum);

    return 0;
}

Sample Output

Sum = 40

Explanation

The + operator adds two numbers and stores the result in the variable sum.

Concepts Covered

  • Arithmetic Operator
  • Addition
  • Integer Variables

2. C Program to Subtract Two Numbers

Problem Statement

Write a C program to subtract one integer from another.

C Solution

#include <stdio.h>

int main()
{
    int first = 50;
    int second = 20;

    int difference = first - second;

    printf("Difference = %d", difference);

    return 0;
}

Sample Output

Difference = 30

Explanation

The subtraction operator (-) subtracts the second value from the first value.

Concepts Covered

  • Arithmetic Operator
  • Subtraction
  • Integer Variables

3. C Program to Multiply Two Numbers

Problem Statement

Write a C program to multiply two integers.

C Solution

#include <stdio.h>

int main()
{
    int first = 12;
    int second = 8;

    int product = first * second;

    printf("Product = %d", product);

    return 0;
}

Sample Output

Product = 96

Explanation

The multiplication operator (*) multiplies two numbers and stores the result in the variable product.

Concepts Covered

  • Arithmetic Operator
  • Multiplication
  • Integer Variables

4. C Program to Divide Two Numbers

Problem Statement

Write a C program to divide two numbers and display the quotient.

C Solution

#include <stdio.h>

int main()
{
    float first = 25;
    float second = 5;

    float quotient = first / second;

    printf("Quotient = %.2f", quotient);

    return 0;
}

Sample Output

Quotient = 5.00

Explanation

The division operator (/) divides one number by another. Using the float data type ensures that decimal values are preserved in the result.

Concepts Covered

  • Arithmetic Operator
  • Division
  • Float Variables
  • Format Specifier %f

5. C Program to Find the Remainder of Two Numbers

Problem Statement

Write a C program to find the remainder when one integer is divided by another.

C Solution

#include <stdio.h>

int main()
{
    int first = 17;
    int second = 5;

    int remainder = first % second;

    printf("Remainder = %d", remainder);

    return 0;
}

Sample Output

Remainder = 2

Explanation

The modulus operator (%) returns the remainder after dividing one integer by another. It works only with integer data types.

Concepts Covered

  • Arithmetic Operator
  • Modulus Operator
  • Integer Division

6. C Program to Increment a Variable Using ++

Problem Statement

Write a C program to increment the value of a variable using the increment (++) operator.

C Solution

#include <stdio.h>

int main()
{
    int number = 10;

    number++;

    printf("Value after Increment = %d", number);

    return 0;
}

Sample Output

Value after Increment = 11

Explanation

The increment operator (++) increases the value of a variable by 1.

Concepts Covered

  • Increment Operator
  • Unary Operator
  • Integer Variables

7. C Program to Decrement a Variable Using --

Problem Statement

Write a C program to decrement the value of a variable using the decrement (--) operator.

C Solution

#include <stdio.h>

int main()
{
    int number = 20;

    number--;

    printf("Value after Decrement = %d", number);

    return 0;
}

Sample Output

Value after Decrement = 19

Explanation

The decrement operator (--) decreases the value of a variable by 1.

Concepts Covered

  • Decrement Operator
  • Unary Operator
  • Integer Variables

8. C Program to Check Whether Two Numbers are Equal

Problem Statement

Write a C program to check whether two numbers are equal using the equality (==) operator.

C Solution

#include <stdio.h>

int main()
{
    int first = 25;
    int second = 25;

    if(first == second)
    {
        printf("Both numbers are Equal");
    }
    else
    {
        printf("Both numbers are Not Equal");
    }

    return 0;
}

Sample Output

Both numbers are Equal

Explanation

The equality operator (==) compares two values. It returns true if both values are equal; otherwise, it returns false.

Concepts Covered

  • Equality Operator
  • Relational Operator
  • if Statement

9. C Program to Find the Largest of Two Numbers

Problem Statement

Write a C program to find the larger of two numbers using the greater-than (>) operator.

C Solution

#include <stdio.h>

int main()
{
    int first = 45;
    int second = 30;

    if(first > second)
    {
        printf("%d is Greater", first);
    }
    else
    {
        printf("%d is Greater", second);
    }

    return 0;
}

Sample Output

45 is Greater

Explanation

The greater-than (>) operator compares two values and identifies the larger number.

Concepts Covered

  • Relational Operator
  • Comparison
  • if Statement

10. C Program to Demonstrate Logical AND (&&) Operator

Problem Statement

Write a C program to demonstrate the Logical AND (&&) operator.

C Solution

#include <stdio.h>

int main()
{
    int age = 22;
    int citizen = 1;

    if(age >= 18 && citizen == 1)
    {
        printf("Eligible to Vote");
    }
    else
    {
        printf("Not Eligible");
    }

    return 0;
}

Sample Output

Eligible to Vote

Explanation

The Logical AND (&&) operator returns true only when both conditions are true.

Concepts Covered

  • Logical AND Operator
  • Relational Operators
  • Conditional Statements

11. C Program to Demonstrate Logical OR (||) Operator

Problem Statement

Write a C program to demonstrate the Logical OR (||) operator.

C Solution

#include <stdio.h>

int main()
{
    int marks = 85;
    int sportsQuota = 1;

    if(marks >= 90 || sportsQuota == 1)
    {
        printf("Eligible for Admission");
    }
    else
    {
        printf("Not Eligible");
    }

    return 0;
}

Sample Output

Eligible for Admission

Explanation

The Logical OR (||) operator returns true if at least one of the given conditions is true.

Concepts Covered

  • Logical OR Operator
  • Conditional Statements
  • Boolean Logic

12. C Program to Demonstrate Logical NOT (!) Operator

Problem Statement

Write a C program to demonstrate the Logical NOT (!) operator.

C Solution

#include <stdio.h>

int main()
{
    int isRain = 0;

    if(!isRain)
    {
        printf("You can go outside.");
    }
    else
    {
        printf("Stay indoors.");
    }

    return 0;
}

Sample Output

You can go outside.

Explanation

The Logical NOT (!) operator reverses the result of a condition.

  • 1 becomes 0
  • 0 becomes 1

Concepts Covered

  • Logical NOT Operator
  • Boolean Values
  • Conditional Logic

13. C Program to Check Whether a Number is Positive

Problem Statement

Write a C program to check whether a number is positive using the greater-than (>) operator.

C Solution

#include <stdio.h>

int main()
{
    int number = 18;

    if(number > 0)
    {
        printf("Positive Number");
    }
    else
    {
        printf("Not a Positive Number");
    }

    return 0;
}

Sample Output

Positive Number

Explanation

The greater-than (>) operator compares the number with zero to determine whether it is positive.

Concepts Covered

  • Relational Operator
  • Comparison
  • if Statement

14. C Program to Find Whether a Number is Even or Odd

Problem Statement

Write a C program to determine whether a number is even or odd using the modulus (%) operator.

C Solution

#include <stdio.h>

int main()
{
    int number = 24;

    if(number % 2 == 0)
    {
        printf("Even Number");
    }
    else
    {
        printf("Odd Number");
    }

    return 0;
}

Sample Output

Even Number

Explanation

If the remainder after dividing a number by 2 is 0, the number is even; otherwise, it is odd.

Concepts Covered

  • Modulus Operator
  • Relational Operator
  • Even and Odd Numbers

15. C Program to Demonstrate Assignment Operators

Problem Statement

Write a C program to demonstrate different assignment operators.

C Solution

#include <stdio.h>

int main()
{
    int number = 10;

    number += 5;
    printf("After += : %d\n", number);

    number -= 3;
    printf("After -= : %d\n", number);

    number *= 2;
    printf("After *= : %d\n", number);

    number /= 4;
    printf("After /= : %d\n", number);

    return 0;
}

Sample Output

After += : 15
After -= : 12
After *= : 24
After /= : 6

Explanation

Assignment operators combine assignment with arithmetic operations, making code shorter and easier to read.

Concepts Covered

  • Assignment Operators
  • Arithmetic Operators
  • Compound Assignment

Chapter Summary

In this chapter, you learned how operators perform calculations, comparisons, and logical operations in C programming. You practiced arithmetic operators (+, -, *, /, %), increment and decrement operators, relational operators (==, >), logical operators (&&, ||, !), and assignment operators (+=, -=, *=, /=). These operators are essential for writing conditions, performing calculations, and solving real-world programming problems.


Key Takeaways

  • Operators are used to perform operations on variables and values.
  • Arithmetic operators perform mathematical calculations.
  • The modulus operator (%) returns the remainder of a division.
  • Increment (++) increases a variable by one.
  • Decrement (--) decreases a variable by one.
  • Relational operators compare two values.
  • Logical operators combine or reverse conditions.
  • Assignment operators simplify arithmetic assignments.
  • Operators are widely used in loops, conditions, and functions.
  • A strong understanding of operators is essential before learning control statements and loops.

Frequently Asked Questions (FAQs)

1. What are operators in C?

Operators are special symbols used to perform mathematical, relational, logical, and assignment operations on variables and values.


2. What are arithmetic operators in C?

Arithmetic operators include:

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • % Modulus

3. What is the difference between = and ==?

  • = is the assignment operator used to assign a value.
  • == is the equality operator used to compare two values.

4. What is the modulus operator used for?

The modulus (%) operator returns the remainder after integer division and is commonly used to check even or odd numbers.


5. What does the increment operator (++) do?

It increases the value of a variable by 1.


6. What does the Logical AND (&&) operator do?

It returns true only if all conditions are true.


7. What does the Logical OR (||) operator do?

It returns true if at least one condition is true.


8. Why are operators important in C programming?

Operators are fundamental to C programming because they enable calculations, comparisons, decision-making, looping, and efficient manipulation of data. They are used in almost every C program.

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top