0% found this document useful (0 votes)
4 views4 pages

Week 5, Data Types, Operators, Expression and Variables

The document provides an overview of fundamental concepts in C programming, including data types, type modifiers, variables, constants, and operators. It explains the five elementary data types, how to declare variables, and the differences between local and global variables. Additionally, it categorizes operators into arithmetic, logical, relational, and bitwise, emphasizing the importance of these concepts for efficient coding and further learning in C.

Uploaded by

Angelica Momo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Week 5, Data Types, Operators, Expression and Variables

The document provides an overview of fundamental concepts in C programming, including data types, type modifiers, variables, constants, and operators. It explains the five elementary data types, how to declare variables, and the differences between local and global variables. Additionally, it categorizes operators into arithmetic, logical, relational, and bitwise, emphasizing the importance of these concepts for efficient coding and further learning in C.

Uploaded by

Angelica Momo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Data Types:
Definition:
In C, data types define the kind of data that can be stored in a
variable. There are five elementary data types:

Character (char): Used to hold ASCII characters or any 8-bit


quantity.
Integer (int): Used to store integer quantities.
Floating-point (float): Used to store real numbers with both
integer and fractional components.
Double floating-point (double): Similar to float but with double
precision.
Void: Used to declare functions that do not return any value or
to create generic pointers.
Example:
char letter = 'A'; // Holds a single character
int number = 100; // Holds an integer
float pi = 3.14; // Holds a floating-point number
double largePi = 3.1415926535; // Holds a double floating-
point number
void function(); // Void function
2. Type Modifiers:
Definition:
Modifiers are used to alter the meaning of the base data types,
allowing for greater precision and range. The following are the
common type modifiers in C:
Signed: Can represent both positive and negative values.
Unsigned: Can only represent non-negative values.
Long: Used to increase the range of integer values.
Short: Used to reduce the range of integer values, saving
memory.
Example:
unsigned int positiveNumber = 50; // Holds only non-negative
integers
long int bigNumber = 100000; // Holds large integers
short int smallNumber = 5; // Holds small integers
3. Variables:
Definition:
Variables are identifiers that store changeable values in a
program. Each variable must be declared with a data type and
a unique name before it is used in the program.
3.1 Variable Declaration:
Variables must be declared before use. The general form of a
declaration is:

Syntax:
type variable1, variable2, variable3;

Example:
int i, j, k; // Declare three integer variables
float x, y; // Declare two floating-point variables
Note: Variables must be separated by commas, and all
declarations must end with a semicolon.
3.2 Types of Variables:
A. Local Variables:
Local variables are declared inside a function and can only be
accessed within that function.
Example:
void myFunction() {
int localVar = 10; // Local variable
printf("%d", localVar);
}
B. Global Variables:
Global variables are declared outside any function and can be
accessed by any part of the program.
Example:
int globalVar = 20; // Global variable

void myFunction() {
printf("%d", globalVar); // Accessing global variable
}

4. Constants:
Definition:
Constants are similar to variables, but their values cannot be
changed during program execution. They are declared using
the const keyword.
Example:
const int maxStudents = 50; // A constant integer with a fixed
value
5. Operators:
Definition:
Operators are symbols used to perform operations on variables
and values. In C, operators are categorized into four classes:

5.1 Arithmetic Operators:


These operators are used for mathematical calculations.
Example:
int sum = 10 + 5; // Adds two numbers
int product = 10 * 5; // Multiplies two numbers
Common arithmetic operators: +, -, *, /, % (modulus)

5.2 Logical Operators:


These operators are used for logical comparisons, returning
either true or false.
Example:
if (x > 5 && y < 10) {
// Executes if both conditions are true
}
Common logical operators: && (AND), || (OR), ! (NOT)

5.3 Relational Operators:

These operators are used to compare two values.


Example:
if (x == y) {
// Executes if x is equal to y
}
Common relational operators: ==, !=, >, <, >=, <=

5.4 Bitwise Operators:

These operators perform operations on the bit level.


Example:
int result = x & y; // Bitwise AND
int result = x | y; // Bitwise OR
Common bitwise operators: &, |, ^, ~, <<, >>
III. Conclusion:
Understanding data types, type modifiers, variables, constants,
and operators is fundamental for any C programmer. These
elements form the building blocks of C programs, enabling
programmers to define how data is stored, manipulated, and
used within a program. Proper use of data types and operators
ensures efficient and functional code that can handle a wide
range of computations.
Takeaway:
Mastering these concepts is crucial to progressing to more
advanced topics in C programming, such as pointers, arrays,
and structures. Students should practice using different data
types, operators, and modifiers to become more comfortable
with variable manipulation in C

You might also like