Lab. 01
Lab. 01
1. Variables in C
2. Constants in C
3. Display in C
4. Inputs in C
5. Expressions & Operators
• Syntax:
<Data_Type> Variable_Name ;
• Examples:
• There is no rule on how long a variable can be. However, only the first 31 characters are
C89 keywords
Microprocessor -Lab.1- Eng.Ahmed Abdel-Gawad 3
➢ Variables in C
• Datatype:
o Determines amount of memory (bytes) a variable requires and range of valid
values that can be stored.
• Syntax:
• Example:
• Syntax:
• Example:
• Syntax:
scanf(“Format”, &Variable_Name);
• Example:
char age;
scanf("%d", &age);
o Example:
Z = X + Y / I; → Expression.
Z,X,Y,I → Operands.
=,+,/ → Operators.
• Operators: Symbols that indicate to the compiler which operation to perform using
X Y || X Y &&
X ! F F F F F F
F T F T T F T F
T F T F T T F F
T T T T T T
Example:
int X =10,Y=0,result;
Example:
int num1 = 10;
int num2 = 1;
int result;
result = num1 & num2;
printf("num1 & num2 = %d \n", result);
result = num1 | num2;
printf("num1 | num2 = %d \n", result);
result = num1 ^ num2;
printf("num1 ^ num2 = %d \n", result);