---
title: "Data types and operators in C"
subject: "Computer Programming"
chapter: 3
key: "semester_1/computer_programming:data-types-operators-precedence"
source: https://www.bctengineer.com/q/semester_1/computer_programming/data-types-operators-precedence
site: BCT Engineering
---

# Data types and operators in C

Computer Programming · Chapter 3: Introduction to ‘C’ programming

- Asked in: 2067 Asoj, 1+4 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/data-types-operators-precedence
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-3

## Question

What is a data type? Explain the operators available in C along with their precedence and associativity.

## Short answer

Data type defines value range, memory size and allowed operations. C operators include arithmetic (+, -, *, /, %), relational, logical, assignment (=, +=), increment, bitwise, conditional (?:), special. Precedence: parentheses highest, comma lowest; associativity mostly left‑to‑right, right‑to‑left for unary/assignment.

## Answer

#### Data type
A **data type** specifies the kind of value a variable can hold, the memory it takes and the operations allowed on it. C has basic types (`int`, `float`, `double`, `char`), derived types (array, pointer, structure, union) and `void`.

#### Operators in C
| Type | Operators | Example |
|---|---|---|
| Arithmetic | `+ - * / %` | `a % b` |
| Relational | `< <= > >= == !=` | `a > b` |
| Logical | `&& \|\| !` | `a>0 && b>0` |
| Assignment | `= += -= *= /= %=` | `a += 5` |
| Increment/decrement | `++ --` | `i++` |
| Bitwise | `& \| ^ ~ << >>` | `a & b` |
| Conditional | `?:` | `max = a>b ? a : b` |
| Special | `sizeof`, `,`, `&`, `*`, `.`, `->` | `sizeof(int)` |

Sample program (output `9 5 14 3 1`, then `1 0 0`, `10`, `10`, `2`):
```c
#include <stdio.h>
int main(void)
{
    int a = 7, b = 2;
    printf("%d %d %d %d %d\n", a + b, a - b, a * b, a / b, a % b);
    printf("%d %d %d\n", a > b, a == b, (a > 3) && (b > 3));
    a += 3;
    printf("%d\n", a);
    printf("%d\n", a > b ? a : b);
    printf("%d\n", a & b);
    return 0;
}
```

Output:
```text
9 5 14 3 1
1 0 0
10
10
2
```

#### Precedence and associativity (highest to lowest)

| Level | Operators | Associativity |
|---|---|---|
| 1 | `() [] . ->` | left to right |
| 2 | `! ~ ++ -- + - (unary) * & sizeof (type)` | right to left |
| 3 | `* / %` | left to right |
| 4 | `+ -` | left to right |
| 5 | `<< >>` | left to right |
| 6 | `< <= > >=` | left to right |
| 7 | `== !=` | left to right |
| 8 | `&` then `^` then `\|` | left to right |
| 9 | `&&` then `\|\|` | left to right |
| 10 | `?:` | right to left |
| 11 | `= += -= *= /= %=` etc. | right to left |
| 12 | `,` | left to right |

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. A data type specifies
   A. the kind of value, memory and allowed operations
   B. only the name
   C. only the value
   D. the compiler
   Answer: A. Defines storage and operations. (Key point: Data type)

2. With a=7,b=2, a/b and a%b give
   A. 3.5 and 1
   B. 3 and 1
   C. 4 and 0
   D. 3 and 2
   Answer: B. Integer division. (Key point: Program output)

3. Which has higher precedence?
   A. + over *
   B. = over *
   C. * over +
   D. ?: over *
   Answer: C. Level 3 vs 4. (Key point: Precedence)

4. 7 & 2 equals
   A. 7
   B. 0
   C. 5
   D. 2
   Answer: D. 111 & 010 = 010. (Key point: Bitwise)

## Related in Computer Programming

- [Precedence and associativity](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aprecedence-associativity) — Computer Programming, chapter 3, asked 2×
- [Global vs local; & and * operators](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aglobal-local-ampersand-star) — Computer Programming, chapter 3

## Related in other subjects

- [Machine learning, GA, operators, areas](https://www.bctengineer.com/question.md?key=semester_6%2Fartificial_intelligence%3Aml-genetic-algorithm-operators-areas) — Artificial Intelligence, chapter 6, asked 2×
- [Distance class relational operators](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Adistance-relational-overload) — Object Oriented Programming, chapter 5
