
Chapter 7:
Operators in C
Author: Er. Mujtaba Ansari
Why Are Operators Important in C Programming?
Have you ever wondered how a C program adds two numbers, compares values, performs calculations, or makes decisions based on a condition?
This is where Operators in C come into play. Operators are special symbols that allow a C program to perform important operations such as calculation, comparison, logical decision-making, and assigning values.
In this chapter, we will learn Operators in C Programming in a simple and beginner-friendly way. You will understand Arithmetic, Relational, Logical, Assignment, Increment/Decrement, Bitwise, and Conditional Operators, along with their syntax and easy programming examples.
If you are learning C Programming, understanding operators is essential because they are used throughout important concepts such as Conditional Statements, Loops, Arrays, and Functions.
📚 C Programming Complete Course Structure
📘 Chapter 1: C Programming Fundamentals
📜 Chapter 2: History and Evolution of C Language
⚙️ Chapter 3: Installing a C Compiler
💻 Chapter 4: Writing Your First C Program
🧩 Chapter 5: Structure of a C Program
📦 Chapter 6: Variables and Data Types
🔢 Chapter 7: Operators in C (Current Chapter)
⌨️ Chapter 8: Input and Output Functions
🔀 Chapter 9: Conditional Statements
🔄 Chapter 10: Loops in C
📊 Chapter 11: Arrays
🔤 Chapter 12: Strings
⚙️ Chapter 13: Functions
👉 Chapter 14: Pointers
🧱 Chapter 15: Structures and Unions
📁 Chapter 16: File Handling
🔹 What is an Operator in C Programming?
Those sign or symbols that perform certain operations are called the operators
and the parameters on which the operation is performed are called the operands.
Eg. A + B
Where: A, B are the operands and ‘+’ operator.
Types of operators:
(1) Arithmatic operator
(2) Relational operator
(3) Assignment operator
(4) Conditional operator
(5) Increment and Decrement operator
(6) Logical operator
(7) Betwise operator
(8) Special operator
(1) Arithmetic operator :
These operators performs the basic mathematical operations like addition, subtraction etc.
The main arithmetic operators in C are:
| Operator | Name | Example |
|---|---|---|
+ | Addition | a + b |
- | Subtraction | a - b |
* | Multiplication | a * b |
/ | Division | a / b |
% | Modulus | a % b |
Addition Operator +
The + operator is used to add two values.
int a = 10;
int b = 20;
int result = a + b;
printf("%d", result);
Output:
30
Subtraction Operator -
The - operator is used to subtract one value from another.
int a = 20;
int b = 10;
printf("%d", a - b);
Output:
10
Multiplication Operator *
The * operator is used to multiply two values.
int a = 5;
int b = 4;
printf("%d", a * b);
Output:
20
Division Operator /
The / operator is used to divide one value by another.
int a = 20;
int b = 5;
printf("%d", a / b);
Output:
4
Modulus Operator %
The % operator returns the remainder after division.
int a = 10;
int b = 3;
printf("%d", a % b);
Output:
1
Because:
10 ÷ 3 = 3 remainder 1
The modulus operator is commonly used to check whether a number is even or odd.
if (number % 2 == 0)
{
printf("Even");
}
(2) Relational operator:
These operators are used to establish a relationship between two operands. In other words, they are used to compare two operands.
Relational operators are used to compare two values.
The result of a relational expression is generally:
1→ True0→ False
The main relational operators are:
| Operator | Meaning |
== | Equal to |
!= | Not equal to |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
Equal To ==
int a = 10;
int b = 10;
printf("%d", a == b);
Output:
1
Both values are equal.
Not Equal !=
int a = 10;
int b = 20;
printf("%d", a != b);
Output:
1
The values are different.
Greater Than >
int a = 20;
int b = 10;
printf("%d", a > b);
Output:
1
Less Than <
int a = 10;
int b = 20;
printf("%d", a < b);
Output:
1
Greater Than or Equal To >=
int age = 18;
printf("%d", age >= 18);
Output:
1
Less Than or Equal To <=
int age = 17;
printf("%d", age <= 18);
Output:
1
For YOU : Important Difference Between = and ==
Beginners often confuse these two operators.
= is the assignment operator:
int a = 10;
== is the equality comparison operator:
if (a == 10)
Remember:
=assigns a value, while==compares two values.
(3) Assignment operator
The assignment operator is used to give or assign the value to the variable.
OR
Assignment operators are used to assign or update values stored in variables.
The basic assignment operator is:
=
Example:
int age = 20;
Here, 20 is assigned to the variable age.
C also provides compound assignment operators.
| Operator | Example | Equivalent To |
= | a = 10 | a = 10 |
+= | a += 5 | a = a + 5 |
-= | a -= 5 | a = a - 5 |
*= | a *= 5 | a = a * 5 |
/= | a /= 5 | a = a / 5 |
%= | a %= 5 | a = a % 5 |
Example:
int a = 10;
a += 5;
printf("%d", a);
Output:
15
(4) Conditional operator
It is the ternary operator consisting of ‘?’ and ‘:’ and it is used for framing the conditional
statements.
The conditional operator is also known as the ternary operator because it works with three operands.
Syntax:
condition ? expression1 : expression2;
Example:
int age = 20;
printf("%s", age >= 18 ? "Adult" : "Minor");
Output:
Adult
The ternary operator is useful when you want to write a simple if-else condition in a single expression.
Example:
int a = 10;
int b = 20;
int max = (a > b) ? a : b;
printf("%d", max);
Output:
20
(5) Increment and Decrement operator
Increment operators are used to increase the value of the variable by 1.
And
Decrement operators are used to decrease the value of the variable by 1.
Increment and decrement operators are used to increase or decrease a variable’s value by 1.
Increment Operator ++
The ++ operator increases a value by 1.
int a = 10;
a++;
printf("%d", a);
Output:
11
This:
a++;
is equivalent to:
a = a + 1;
Decrement Operator --
The -- operator decreases a value by 1.
int a = 10;
a--;
printf("%d", a);
Output:
9
This:
a--;
is equivalent to:
a = a - 1;
Pre-Increment and Post-Increment
The increment operator can be used in two forms.
Pre-Increment
++a;
In pre-increment, the value is increased first and then used in the expression.
Example:
int a = 10;
int b = ++a;
printf("a = %d\n", a);
printf("b = %d", b);
Output:
a = 11
b = 11
Post-Increment
a++;
In post-increment, the current value is used first and then increased.
int a = 10;
int b = a++;
printf("a = %d\n", a);
printf("b = %d", b);
Output:
a = 11
b = 10
The same concept applies to pre-decrement and post-decrement.
Prefix and Postfix Operators in C
| Type | Prefix | Postfix |
|---|---|---|
| Increment | ++A | A++ |
| Decrement | --A | A-- |
1. Prefix Increment
Example: ++A
The value of A is increased by 1 before it is used in the expression.
2. Postfix Increment
Example: A++
The current value of A is used first, and then its value is increased by 1.
3. Prefix Decrement
Example: --A
The value of A is decreased by 1 before it is used in the expression.
4. Postfix Decrement
Example: A--
The current value of A is used first, and then its value is decreased by 1.
Simple rule to remember:
++A→ Increase first, then useA++→ Use first, then increase--A→ Decrease first, then useA--→ Use first, then decrease
1. Post-Increment Example
#include <stdio.h>
int main()
{
int A = 15, x;
x = A++;
printf("x = %d\n", x);
printf("A = %d\n", A);
return 0;
}
Output:
x = 15
A = 16
Explanation:
In post-increment, the current value of A is assigned to x first. After that, the value of A is increased by 1.
2. Pre-Increment Example
#include <stdio.h>
int main()
{
int A = 9, x;
x = ++A + 6;
printf("A = %d\n", A);
printf("x = %d\n", x);
return 0;
}
Output:
A = 10
x = 16
Explanation:
In pre-increment, the value of A is increased first from 9 to 10. Then 10 + 6 is calculated, so the value of x becomes 16.
3. Post-Increment with Addition
#include <stdio.h>
int main()
{
int A = 10, x;
x = A++ + 9;
printf("x = %d\n", x);
printf("A = %d\n", A);
return 0;
}
Output:
x = 19
A = 11
Explanation:
The current value of A, which is 10, is used first:
10 + 9 = 19
After that, the value of A is increased to 11.
4. Multiple Increment Operators in One Expression
The original example was:
int A = 5, x;
x = ++A + A++;
The output was given as:
A = 7
x = 12
However, this is not a valid example for standard C programming.
The variable A is modified more than once in the same expression:
++A
A++
The order of these modifications is not properly sequenced, so the expression has undefined behavior.
Therefore, you should not show A = 7 and x = 12 as the fixed output.
5. Multiple Pre-Increment and Post-Increment Operators
Original example:
int A = 9, x;
x = ++A + A++ + ++A + A++ + A;
The given output was:
A = 13
x = 55
This should not be presented as a fixed output in standard C.
The variable A is modified multiple times within the same expression:
++A
A++
++A
A++
This results in undefined behavior.
Therefore, there is no guaranteed output for this program.
6. Another Multiple Increment Example
Original example:
int A = 5, x;
x = ++A + A++ + A++ + A;
The given output was:
A = 8
x = 24
Again, this is undefined behavior in standard C because A is modified multiple times in the same expression.
Therefore, A = 8 and x = 24 should not be given as a guaranteed output.
Important Note for YOU
Avoid writing multiple ++ or -- operations on the same variable within a single expression when teaching standard C. It can lead to undefined behavior and confusion for beginners.
7. Post-Increment in an if Condition
This example is correct:
#include <stdio.h>
int main()
{
int A = 9;
if (A++ >= 10)
{
printf("Hi");
}
else
{
printf("Bye");
}
return 0;
}
Output:
Bye
Explanation
The condition is:
A++ >= 10
Since A++ is a post-increment operator, the current value of A is used for the comparison first.
The current value is 9, so the comparison becomes:
9 >= 10
This is false, so the else block executes and prints:
Bye
After the comparison, the value of A is increased from 9 to 10.
If we also print the final value:
#include <stdio.h>
int main()
{
int A = 9;
if (A++ >= 10)
{
printf("Hi\n");
}
else
{
printf("Bye\n");
}
printf("A = %d\n", A);
return 0;
}
Output:
Bye
A = 10
Key Difference Between Prefix and Postfix
| Operator | Meaning | Order of Operation |
|---|---|---|
++A | Prefix Increment | Increment first, then use the value |
A++ | Postfix Increment | Use the value first, then increment |
--A | Prefix Decrement | Decrement first, then use the value |
A-- | Postfix Decrement | Use the value first, then decrement |
Easy rule to remember:
Prefix: Change the value first, then use it.
Postfix: Use the current value first, then change it.
(6) Logical operator
These operators perform operations on the logical value ie. 0 or 1.
Logical operators are used to perform operations on logical values. In C, 0 represents false, while a non-zero value represents true. In truth tables, we commonly use 0 and 1 to represent false and true.
C provides three logical operators:
| Operator | Name |
|---|---|
&& | Logical AND |
|| | Logical OR |
! | Logical NOT |
Truth Table for Logical AND (&&) and Logical OR (||)
┌───────────────────────────────────────┐
│ AND (&&) and OR (||) │
├─────────┬─────────┬─────────┬─────────┤
│ A │ B │ A && B │ A || B │
├─────────┼─────────┼─────────┼─────────┤
│ 0 │ 0 │ 0 │ 0 │
│ 0 │ 1 │ 0 │ 1 │
│ 1 │ 0 │ 0 │ 1 │
│ 1 │ 1 │ 1 │ 1 │
└─────────┴─────────┴─────────┴─────────┘
Logical AND (&&)
The Logical AND operator returns 1 only when both operands are true (1). Otherwise, it returns 0.
Example:
1 && 1 = 1
1 && 0 = 0
0 && 1 = 0
0 && 0 = 0
Rule: Both conditions must be true.
Logical OR (||)
The Logical OR operator returns 1 when at least one operand is true (1). It returns 0 only when both operands are 0.
Example:
1 || 1 = 1
1 || 0 = 1
0 || 1 = 1
0 || 0 = 0
Rule: At least one condition must be true.
Truth Table for Logical NOT (!)
The Logical NOT operator works with a single operand and reverses its logical value.
┌─────────────────────┐
│ Logical NOT (!) │
├─────────┬───────────┤
│ A │ !A │
├─────────┼───────────┤
│ 0 │ 1 │
│ 1 │ 0 │
└─────────┴───────────┘
Rule: The NOT operator reverses the logical value.
!0 = 1
!1 = 0
Note:
&&→ AND → Both conditions must be true.||→ OR → At least one condition must be true.!→ NOT → Reverses the logical value.
(7) Betwise operator
Bitwise operators perform operations directly on the individual bits of integer values. These operators perform operations at the bit level. Since computers represent numbers internally in binary form (0 and 1), these operators work at the bit level.
Bitwise operators are commonly used in embedded systems, system programming, device programming, networking, and low-level programming.
Main Bitwise Operators
| Operator | Name | Purpose |
|---|---|---|
& | Bitwise AND | Performs AND operation on each bit |
| | Bitwise OR | Performs OR operation on each bit |
^ | Bitwise XOR | Returns 1 when bits are different |
~ | Bitwise NOT | Reverses each bit |
<< | Left Shift | Shifts bits to the left |
>> | Right Shift | Shifts bits to the right |
1. Bitwise AND (&)
The Bitwise AND operator compares corresponding bits. The result is 1 only when both bits are 1.
┌───────────────────────┐
│ Bitwise AND (&) │
├───────┬───────┬───────┤
│ A │ B │ A & B │
├───────┼───────┼───────┤
│ 0 │ 0 │ 0 │
│ 0 │ 1 │ 0 │
│ 1 │ 0 │ 0 │
│ 1 │ 1 │ 1 │
└───────┴───────┴───────┘
Example
int a = 5;
int b = 3;
printf("%d", a & b);
Binary calculation:
5 = 0101
3 = 0011
----
& 0001
Output:
1
2. Bitwise OR (|)
The Bitwise OR operator returns 1 when at least one of the corresponding bits is 1.
┌───────────────────────┐
│ Bitwise OR (|) │
├───────┬───────┬───────┤
│ A │ B │ A | B │
├───────┼───────┼───────┤
│ 0 │ 0 │ 0 │
│ 0 │ 1 │ 1 │
│ 1 │ 0 │ 1 │
│ 1 │ 1 │ 1 │
└───────┴───────┴───────┘
Example
int a = 5;
int b = 3;
printf("%d", a | b);
5 = 0101
3 = 0011
----
| 0111
Output:
7
3. Bitwise XOR (^)
The Bitwise XOR operator returns 1 when the corresponding bits are different. If the bits are the same, it returns 0.
┌───────────────────────┐
│ Bitwise XOR (^) │
├───────┬───────┬───────┤
│ A │ B │ A ^ B │
├───────┼───────┼───────┤
│ 0 │ 0 │ 0 │
│ 0 │ 1 │ 1 │
│ 1 │ 0 │ 1 │
│ 1 │ 1 │ 0 │
└───────┴───────┴───────┘
Example
int a = 5;
int b = 3;
printf("%d", a ^ b);
5 = 0101
3 = 0011
----
^ 0110
Output:
6
4. Bitwise NOT (~)
The Bitwise NOT operator reverses every bit of a value.
0 → 1
1 → 0
┌─────────────────────┐
│ Bitwise NOT (~) │
├───────┬─────────────┤
│ A │ ~A │
├───────┼─────────────┤
│ 0 │ 1 │
│ 1 │ 0 │
└───────┴─────────────┘
Example:
int a = 5;
printf("%d", ~a);
For a typical modern system using two’s complement representation:
~5 = -6
5. Left Shift (<<)
The Left Shift operator shifts the bits toward the left.
int a = 5;
printf("%d", a << 1);
5 = 0101
↓
1010
5 << 1 = 10
Output:
10
6. Right Shift (>>)
The Right Shift operator shifts the bits toward the right.
int a = 8;
printf("%d", a >> 1);
8 = 1000
↓
0100
8 >> 1 = 4
Output:
4
Quick Revision Specially For You
& → Bitwise AND → Both bits must be 1
| → Bitwise OR → At least one bit must be 1
^ → Bitwise XOR → Different bits give 1
~ → Bitwise NOT → Reverses the bits
<< → Left Shift → Shifts bits left
>> → Right Shift → Shifts bits right
(8) Special operator
Special operators are operators that perform specific tasks that do not fall directly into categories such as arithmetic, relational, or logical operations. They are especially useful for working with memory, variables, structures, pointers, and expressions.
Some commonly used special operators in C are:
| Operator | Name | Main Use |
|---|---|---|
, | Comma Operator | Evaluates multiple expressions |
sizeof | Size-of Operator | Finds the size of a type or object in bytes |
. | Dot / Member Access Operator | Accesses a structure or union member |
& | Address-of Operator | Gets the memory address of a variable |
* | Dereference Operator | Accesses the value stored at a pointer’s address |
-> | Arrow / Pointer Member Access Operator | Accesses a structure or union member through a pointer |
1. Comma Operator (,)
The comma operator is used to evaluate multiple expressions from left to right. The value of the last expression becomes the result of the complete expression.
Example
#include <stdio.h>
int main()
{
int A;
A = (2, 4);
printf("%d", A);
return 0;
}
Output:
4
Explanation
The expressions are evaluated from left to right:
2 → evaluated first
4 → evaluated second
The value of the last expression, 4, is assigned to A.
Therefore:
A = 4
Important: The comma operator should not be confused with commas used simply as separators in function arguments or variable declarations.
2. sizeof Operator
The sizeof operator is used to determine the amount of memory occupied by a data type or object, measured in bytes.
It can be used with:
- Data types
- Variables
- Arrays
- Expressions
Syntax
sizeof(data_type)
or
sizeof(variable)
The result of sizeof has type size_t, so %zu is the recommended format specifier when printing it.
Example 1: Using sizeof with a Data Type
#include <stdio.h>
int main()
{
size_t S;
S = sizeof(int);
printf("%zu", S);
return 0;
}
The output depends on the system and compiler. On many modern systems:
4
This means an int occupies 4 bytes on that particular system.
Note: The size of a C data type is implementation-dependent. Do not assume that
intis always 2 or 4 bytes.
Example 2: Using sizeof with float
#include <stdio.h>
int main()
{
size_t S;
S = sizeof(float);
printf("%zu", S);
return 0;
}
On most modern systems, the output is:
4
This means a float commonly occupies 4 bytes.
Example 3: Using sizeof with a String Literal
Consider:
#include <stdio.h>
int main()
{
size_t S;
S = sizeof("abc");
printf("%zu", S);
return 0;
}
Output:
4
Why?
The string literal "abc" contains three characters:
a b c \0
The \0 is the null character that terminates the string, so the size is 4 bytes when char occupies one byte.
Therefore:
sizeof("abc") = 4
Example 4: Using sizeof with a Variable
#include <stdio.h>
int main()
{
int s = 10;
printf("%zu", sizeof(s));
return 0;
}
On a typical modern system, the output is:
4
The exact size depends on the implementation.
3. Dot Operator (.) — Member Access Operator
The dot (.) operator, also called the member access operator, is used to access a member of a structure or union variable.
Example
#include <stdio.h>
struct Student
{
int age;
};
int main()
{
struct Student s;
s.age = 20;
printf("%d", s.age);
return 0;
}
Output:
20
Here:
s.age
uses the dot operator to access the age member of the structure variable s.
Simple Rule
.→ Used to access a structure or union member through a structure or union variable.
4. Address-of Operator (&)
The address-of operator (&) is used to obtain the memory address of a variable.
Example
#include <stdio.h>
int main()
{
int A = 10;
printf("%p", (void *)&A);
return 0;
}
The output will be a memory address, which can vary each time the program runs.
For example:
0x7ffd1234abcd
The actual address depends on the system and execution.
The address-of operator is especially important when learning pointers in C.
5. Dereference Operator (*)
The dereference operator (*) is used with a pointer to access the value stored at the memory address held by that pointer.
Example
#include <stdio.h>
int main()
{
int A = 10;
int *p = &A;
printf("%d", *p);
return 0;
}
Output:
10
How It Works
A = 10
│
│ &A
▼
Memory Address
│
▼
p
│
│ *p
▼
10
Here:
&Agets the address ofA.pstores that address.*paccesses the value stored at that address.
Important
The * symbol has different uses in C. For example:
int *p;
Here, * is used in a pointer declaration.
But:
*p
uses * as the dereference operator.
6. Arrow Operator (->)
The arrow operator (->), also called the pointer member access operator, is used to access a member of a structure or union through a pointer.
Example
#include <stdio.h>
struct Student
{
int age;
};
int main()
{
struct Student s = {20};
struct Student *p = &s;
printf("%d", p->age);
return 0;
}
Output:
20
Here:
p->age
accesses the age member through the structure pointer p.
The following two expressions are equivalent:
p->age
and
(*p).age
Simple Rule
.→ Access a member through a structure/union variable.->→ Access a member through a pointer to a structure/union.
Dot (.) vs Arrow (->)
| Operator | Used With | Example |
|---|---|---|
. | Structure/union variable | s.age |
-> | Pointer to structure/union | p->age |
Very Simple Example
Structure variable:
s.age
↑
│
Dot (.)
Structure pointer:
p->age
↑
│
Arrow (->)
Revision of Special Operators
, → Comma Operator
sizeof → Finds size in bytes
. → Accesses structure/union member
& → Gets the address of a variable
* → Dereferences a pointer
-> → Accesses a structure/union member through a pointer
Important Notes for YOU
- The comma operator evaluates expressions from left to right and produces the value of the last expression.
- The
sizeofoperator gives the size of a type or object in bytes. - The dot operator (
.) accesses members through a structure or union variable. - The address-of operator (
&) gives the address of a variable. - The dereference operator (
*) accesses the value stored at a pointer’s address. - The arrow operator (
->) accesses structure or union members through a pointer.
Frequently Asked Questions (FAQs)
1. What are operators in C?
Operators in C are special symbols used to perform operations on values, variables, and expressions. Examples include +, -, *, /, ==, &&, and =.
2. What are the main types of operators in C?
The main types of operators in C are arithmetic, relational, logical, assignment, increment/decrement, bitwise, conditional, and special operators.
3. What is the difference between = and == in C?
= is the assignment operator, used to assign a value to a variable, while == is the equality operator, used to compare two values.
int a = 10; // Assignment
if (a == 10) // Comparison
4. What is the difference between ++a and a++?
++a is pre-increment, which increases the value before it is used. a++ is post-increment, which uses the current value first and then increases it.
5. What is the difference between && and & in C?
&& is the logical AND operator and works with logical conditions. & is the bitwise AND operator and performs an operation on the individual bits of integer values.
6. What is the % operator used for in C?
The % operator is called the modulus operator. It returns the remainder of an integer division.
int result = 10 % 3;
The result is:
1
7. What is the conditional or ternary operator in C?
The ?: operator is called the conditional or ternary operator. It provides a short way to write a simple conditional expression.
int max = (a > b) ? a : b;
8. What are bitwise operators in C?
Bitwise operators perform operations directly on the individual bits of integer values. The main bitwise operators are &, |, ^, ~, <<, and >>.
9. What is the sizeof operator in C?
The sizeof operator is used to determine the amount of memory occupied by a data type or object, measured in bytes.
printf("%zu", sizeof(int));
The exact result depends on the C implementation and platform.
10. What is the difference between . and -> operators in C?
The dot (.) operator is used to access a member through a structure or union variable, while the arrow (->) operator is used to access a member through a pointer to a structure or union.
student.age; // Using .
ptr->age; // Using ->
These two operators become particularly important when learning Structures, Unions, and Pointers in C.
Top 10 Exam & Interview Questions on Operators in C
Important for Exams & IT Corporate Interviews
1. Which operator is used for assignment in C?
A) ==
B) =
C) !=
D) >=
Correct Answer: B) =
2. What is the output of the following code?
int a = 5, b = 2;
printf("%d", a + b);
A) 2
B) 3
C) 7
D) 10
Correct Answer: C) 7
3. Which operator is known as the modulus operator in C?
A) /
B) %
C) //
D) &
Correct Answer: B) %
4. What is the difference between ++a and a++?
A) Both work exactly the same
B) ++a increments after use, while a++ increments before use
C) ++a increments before use, while a++ increments after use
D) Both decrement the value
Correct Answer: C) ++a increments before use, while a++ increments after use
5. Which of the following is a logical AND operator in C?
A) &
B) &&
C) ||
D) !
Correct Answer: B) &&
Note:
&is the bitwise AND operator, while&&is the logical AND operator.
6. What will be the output?
int a = 5, b = 3;
printf("%d", a & b);
A) 1
B) 7
C) 6
D) 8
Correct Answer: A) 1
Explanation:
5 = 0101
3 = 0011
----
& 0001
Therefore, the result is 1.
7. Which operator is used to find the size of a data type or variable?
A) size()
B) sizeof
C) length()
D) memory()
Correct Answer: B) sizeof
8. Which operator is used to access a structure member through a structure variable?
A) ->
B) .
C) *
D) &
Correct Answer: B) .
Example:
student.age
Here, . is used to access the age member.
9. Which operator is used to access a structure member through a pointer?
A) .
B) &
C) ->
D) ::
Correct Answer: C) ->
Example:
ptr->age
10. What is the output of the following code?
int a = 10;
int *p = &a;
printf("%d", *p);
A) Address of a
B) 0
C) 10
D) Error
Correct Answer: C) 10
Explanation:&a gets the address of a, while *p dereferences the pointer and accesses the value stored at that address.

Mujtaba Ansari is a Software Engineer, Founder & CEO of The Tech Earth. He writes about technology, AI, software, cybersecurity, blogging, Health tech, Agri Tech and digital trends to help readers stay updated with the latest innovations.
