ESKISEHIR TECHNICAL UNIVERSITY
2025–2026 FALL SEMESTER
INTRODUCTION TO PROGRAMMING COURSE
WEEK 4: TOKENS IN C-
KEYWORDS, IDENTIFIERS, CONSTANTS,
OPERATORS
Assoc. Prof. Dr. Nuray Gedik
THE OUTLINE
• Tokens in C
• Keywords
• Constants
• Variables
• Operators
PREVIOUS WEEK: FLOWGORITHM EXERCISES
• Draw the flowchart to find the factorial of a given number
PREVIOUS WEEK:
FLOWGORITHM EXERCISES
• Draw the flowchart to find the
factorial of a given number
PREVIOUS WEEK: FLOWGORITHM EXERCISES
• Find the sum of odd numbers between 1 and 99
PREVIOUS WEEK:
FLOWGORITHM EXERCISES
• Find the sum of odd numbers
between 1 and 99
INTRODUCTION TO C: BASICS
• C is a compiled language.
• That means the computer will not interpret the code directly. To
compile the code, you need a program called a compiler.
• C is used for programming complex systems with high performance:
• Operating systems
• Microcontrollers (e.g, airplanes)
• Embedded processors (e.g. phones, portable electronics)
INTRODUCTION TO C
PREVIOUS WEEK: TOKENS IN C
• A token in C can be defined as the smallest individual element of the C programming
language that is meaningful to the compiler.
• It is the basic component of a C program
[Link]
GET STARTED WITH C
Let’s meet the IDE
&
Write the First C Program
REMEMBER:
• Compilers & IDEs (Integrated Development Environment):
• Dev C++,
• Visual Studio,
• Code:blocks
• gcc
REMEMBER:
DEV C++
• Dev-C++ is a full-featured C and
C++ Integrated Development
Environment (IDE) for Windows
platforms.
• Millions of developers, students and
researchers use Dev-C++ since the
first version was released in 1998.
You can download from: [Link]
[Link]
CODE::BLOCKS
You can download from: [Link]
THE VERY FIRST C PROGRAM
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
THE VERY FIRST C PROGRAM
#include <stdio.h>
int main() {
printf("Hello World!\n"); The new line character
printf("I like learning C!");
return 0;
}
BASIC TOKENS IN C
KEYWORDS
• The keywords are pre-defined or reserved words in a programming language.
• Each keyword is meant to perform a specific function in a program.
• Since keywords are referred names for a compiler, they can’t be used as
variable names because by doing so, we are trying to assign a new meaning to
the keyword which is not allowed.
• You cannot redefine keywords. However, you can specify the text to be
substituted for keywords before compilation by using C preprocessor
directives.
KEYWORDS
A SAMPLE CODE: CHAR KEYWORD
// C program to demonstrate char keyword
#include <stdio.h>
// Driver code
int main() {
char c = 'a';
printf("%c", c);
return 0;
}
IDENTIFIERS
• Identifiers are used as the general terminology for the naming of
variables, functions, and arrays.
• A variable is a named storage location in a program that holds a value
which can change during execution.
• Think of it as a container or labeled box in memory — you can store
data in it, read from it, or replace its contents.
IDENTIFIERS
• These are user-defined names consisting of an arbitrarily long sequence
of letters and digits with either a letter or the underscore(_) as a first
character.
• Identifier names must differ in spelling and case from any keywords.
• You cannot use keywords as identifiers; they are reserved for special
use.
• Once declared, you can use the identifier in later program statements
to refer to the associated value. A special identifier called a statement
label can be used in goto statements.
IDENTIFIERS: RULES FOR NAMING
• They must begin with a letter or underscore(_).
• They must consist of only letters, digits, or underscore. No other special character is allowed.
• It should not be a keyword.
• It must not contain white space. It should be up to 31 characters long as only the first 31
characters are significant.
• Note: Identifiers are case-sensitive so names like variable and Variable will be treated as different.
• For example,
• main: method name.
• a: variable name.
#include <stdio.h> IDENTIFIERS
int main(void) {
// Declaration + initialization
• Ex: int age = 20; // integer
float height = 1.72f; // floating-point
char grade = 'A'; // single character (use single quotes)
char name[20] = "Kerem"; // string as a char array
printf("Name: %s\nAge: %d\nHeight: %.2f\nGrade: %c\n",
name, age, height, grade);
return 0;
}
?
Which of the following is a valid identifier in C?
A) 3variable
B) int$
C) my-Var
D) float#var
E) var_name
CONSTANTS
• The constants refer to the variables with fixed values. They are like
normal variables but with the difference that their values cannot be
modified in the program once they are defined.
• Constants may belong to any of the data types.
• Examples: const int c_var = 20;
const int* const ptr = &c_var;
STRINGS
• Strings are nothing but an array of characters ended with a null character
(‘\0’). This null character indicates the end of the string.
• Strings are always enclosed in double quotes. Whereas, a character is
enclosed in single quotes in C and C++.
• Examples of String:
• char string[20] = {‘g’, ’e’, ‘e’, ‘k’, ‘s’, ‘f’, ‘o’, ‘r’, ‘g’, ’e’, ‘e’, ‘k’, ‘s’, ‘\0’};
• char string[20] = “geeksforgeeks”;
• char string [] = “geeksforgeeks”;
SPECIAL SYMBOLS
• The following special symbols are used in C having some special meaning and thus,
cannot be used for some other purpose. Some of these are listed below:
• Brackets[]: Opening and closing brackets are used as array element references. These
indicate single and multidimensional subscripts.
• Parentheses(): These special symbols are used to indicate function calls and function
parameters.
• Braces{}: These opening and ending curly braces mark the start and end of a block of
code containing more than one executable statement.
• Comma (, ): It is used to separate more than one statement like for separating
parameters in function calls.
• Colon(:): It is an operator that essentially invokes something called an initialization list.
SPECIAL SYMBOLS
• Semicolon(;): It is known as a statement terminator. It indicates the end of one
logical entity. That’s why each individual statement must be ended with a
semicolon.
• Asterisk (*): It is used to create a pointer variable and for the multiplication of
variables.
• Assignment operator(=): It is used to assign values and for logical operation
validation.
• Pre-processor (#): The preprocessor is a macro processor that is used
automatically by the compiler to transform your program before actual compilation.
• Period (.): Used to access members of a structure or union.
• Tilde(~): Bitwise One’s Complement Operator.
OPERATORS
• Operators are symbols that trigger an action when applied to C variables and other objects. The
data items on which operators act are called operands.
• Unary Operators: Those operators that require only a single operand to act upon are known as unary operators. For
Example increment and decrement operators
• Binary Operators: Those operators that require two operands to act upon are called binary operators. Binary
operators can further are classified into:
• Arithmetic operators
• Relational Operators
• Logical Operators
• Assignment Operators
• Bitwise Operator
• Ternary Operator: The operator that requires three operands to act upon is called the ternary operator. Conditional
Operator(?) is also called the ternary operator.
LET’S START: OPERATORS
• Operators are symbols that trigger an action when applied to C variables and other objects.
• The data items on which operators act are called operands.
• For example: + is an operator to perform addition.
OPERATOR TYPES
• Unary Operators: Those operators that require only a single operand to act upon are known as
unary operators. For example, increment and decrement operators
• Binary Operators: Those operators that require two operands to act upon are called binary
operators. Binary operators can further are classified into:
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Assignment Operators
• Bitwise Operator
• Ternary Operator: The operator that requires three operands to act upon is called the ternary
operator. Conditional Operator(?) is also called the ternary operator.
UNARY OPERATORS
An operator is said to be unary if it takes just a single operand, unlike a binary
operator which needs two operands.
+ Plus Operator: It doesn’t affect the value of its operand:
• int x = +5;
• printf("%d\n", x); // Output: 5
- Minus Operator: It negates the value of its operand:
• int x = -5;
• printf("%d\n", x); // Output: -5
UNARY OPERATORS
++ Increment Operator: It increases the value of its operand by 1:
• int x = 5;
• x++;
• printf("%d\n", x); // Output: 6
-- Decrement Operator: It decreases the value of its operand by 1:
• int x = 5;
• x--;
• printf("%d\n", x); // Output: 4
UNARY OPERATORS
The Difference between Prefix and Postfix Increment/Decrement
• The prefix increment (++x) or decrement (--x) operator changes the value
of x first, then the new value is used in the expression.
• int x = 5;
• printf("%d\n", ++x); // Output: 6
UNARY OPERATORS
The Difference between Prefix and Postfix Increment/Decrement
• Conversely, the postfix increment (x++) or decrement (x--) operator uses
the value of x in the expression first, and then changes the value.
• int x = 5;
• printf("%d\n", x++); // Output: 5
• printf("%d\n", x); // Output: 6
UNARY OPERATORS
Examples: Increment/Decrement
int a=0, b; a becomes 1
b= ++a; b becomes 1
int a=0, b; a becomes 1
b= a++; b becomes 0
UNARY OPERATORS
Examples: Increment/Decrement
int a=2, b, c=5; a becomes 1
b= --a + c; c becomes 5
b becomes 6
int a=2, b; c=5 a becomes 2
b= a++ + --c; c becomes 4
b becomes 6
UNARY OPERATORS
& Address of Operator: It returns the memory address of its operand:
• int x = 5;
• printf("%p\n", &x); // Output: Memory address of x
sizeof() Operator: It returns the size (in bytes) of its operand:
• int x;
• printf("%zu\n", sizeof(x)); // Output: Size of integer on your system, commonly 4
BINARY OPERATORS
1. Arithmetic Operators
Operator Meaning of Operator
+ addition or unary plus
- subtraction or unary minus
* multiplication
/ division
% remainder after division (modulo division)
BINARY OPERATORS
// Working of arithmetic operators
#include <stdio.h>
1. Arithmetic Operators int main()
{
int a = 9, b = 4, c;
c = a+b;
printf("a+b = %d \n",c);
c = a-b;
printf("a-b = %d \n",c);
c = a*b;
printf("a*b = %d \n",c);
c = a/b;
printf("a/b = %d \n",c);
c = a%b;
printf("Remainder when a divided by b = %d \n",c);
return 0;
}
#include <stdio.h>
int main()
BINARY OPERATORS
{
int a = 25, b = 5;
1. Arithmetic Operators: Exercise: printf("a + b = %d\n", a + b);
printf("a - b = %d\n", a - b);
Output: printf("a * b = %d\n", a * b);
a + b = 30 printf("a / b = %d\n", a / b);
a - b = 20
printf("a % b = %d\n", a % b);
a * b = 125
printf("+a = %d\n", +a);
a / b = 5
a % b = 0 printf("-a = %d\n", -a);
+a = 25 printf("a++ = %d\n", a++);
-a = -25 printf("a-- = %d\n", a--);
a++ = 25 return 0;
a-- = 26 }
BINARY OPERATORS
2. Relational Operators: used for the comparison of the two operands
Symbol Operator Description Syntax
Returns true if the left operand is less than the right
< Less than a<b
operand. Else false
Returns true if the left operand is greater than the right
> Greater than a>b
operand. Else false
Returns true if the left operand is less than or equal to the
<= Less than or equal to a <= b
right operand. Else false
Returns true if the left operand is greater than or equal to
>= Greater than or equal to a >= b
right operand. Else false
== Equal to Returns true if both the operands are equal. a == b
!= Not equal to Returns true if both the operands are NOT equal. a != b
BINARY OPERATORS
2. Relational Operators
// C program to illustrate the relational operators
BINARY OPERATORS
#include <stdio.h>
int main()
{
2. Relational Operators: Exercise:
int a = 25, b = 5;
printf("a < b : %d\n", a < b);
printf("a > b : %d\n", a > b);
printf("a <= b: %d\n", a <= b);
printf("a >= b: %d\n", a >= b);
printf("a == b: %d\n", a == b);
printf("a != b : %d\n", a != b);
return 0;
}
BINARY OPERATORS
3. Logical Operators: used to combine two or more conditions/constraints or
to complement the evaluation of the original condition in consideration
Symbol Operator Description Syntax
Returns true if both
&& Logical AND a && b
the operands are true.
Returns true if both
|| Logical OR or any of the operand a || b
is true.
Returns true if the
! Logical NOT !a
operand is false.
BINARY OPERATORS
3. Logical Operators
Input1 Input2 Input1 && Input2
true (1) true (1) true (1)
true (1) false(0) false(0)
false(0) true(1) false(0)
false(0) false(0) false(0)
BINARY OPERATORS
3. Logical Operators
|| Logical OR (a>3) | | (b<3) true
Input1 Input2 Input1 && Input2
true (1) true (1) true (1)
true (1) false(0) true (1)
false(0) true(1) true (1)
false(0) false(0) false(0)
BINARY OPERATORS
3. Logical Operators
! Logical NOT ! (a > 3), (3) true
Input1 ! Input1
true (1) false(0)
false(0) true (1)
// C program to illustrate the logical operators
BINARY OPERATORS
#include <stdio.h>
int main()
3. Logical Operators {
int a = 25, b = 5;
// using operators and printing results
printf("a && b : %d\n", (a>5) && (b>3));
printf("a || b : %d\n", (a>5) || (b>3));
printf("!a: %d\n", !a);
return 0;
}
BINARY OPERATORS
4. Bitwise Operators: used to perform bit-level operations on the operands. The
operators are first converted to bit-level and then the calculation is performed on
the operands.
Symbol Operator Description Syntax
Performs bit-by-bit AND operation and returns the
& Bitwise AND a&b
result.
| Bitwise OR Performs bit-by-bit OR operation and returns the result. a|b
Performs bit-by-bit XOR operation and returns the
^ Bitwise XOR a^b
result.
Bitwise First
~ Flips all the set and unset bits on the number. ~a
Complement
Shifts the number in binary form by one place in the
<< Bitwise Leftshift a << b
operation and returns the result.
Shifts the number in binary form by one place in the
>> Bitwise Rightshift a >> b
operation and returns the result.
BINARY OPERATORS
4. Bitwise Operators
OR 7
BINARY OPERATORS
4. Bitwise Operators
• a is 5, the binary representation is 0000 0101
• b is 3, the binary representation is 0000 0011
Bitwise AND sets each bit to 1 if both bits are 1.
• Since only the last bit is 1 both in a and b, the result is 0000 0001, which is 1
BINARY OPERATORS
4. Bitwise Operators
• a is 5, the binary representation is 0000 0101
• b is 3, the binary representation is 0000 0011
Bitwise OR sets each bit to 1 if at least one of the corresponding bits is 1.
• Since only the last three bit is either 1 in a and b, the result is 0000 0111, which is 7
BINARY OPERATORS
// C program to illustrate the bitwise operators
#include <stdio.h>
4. Bitwise Operators
int main()
{
int a = 25, b = 5;
printf("a & b: %d\n", a & b);
printf("a | b: %d\n", a | b);
printf("a ^ b: %d\n", a ^ b);
printf("~a: %d\n", ~a);
printf("a >> b: %d\n", a >> b);
printf("a << b: %d\n", a << b);
return 0;
}
BINARY OPERATORS
5. Assignment Operators
Symbol Operator Description Syntax
= Simple Assignment Assign the value of the right operand to the left operand. a=b
+= Plus and assign Add the right operand and left operand and assign this value to the left operand. a += b
-= Minus and assign Subtract the right operand and left operand and assign this value to the left operand. a -= b
*= Multiply and assign Multiply the right operand and left operand and assign this value to the left operand. a *= b
Divide the left operand with the right operand and assign this value to the left
/= Divide and assign a /= b
operand.
BINARY OPERATORS
5. Assignment Operators
Symbol Operator Description Syntax
Assign the remainder in the division of left operand with the right operand to
%= Modulus and assign a %= b
the left operand.
&= AND and assign Performs bitwise AND and assigns this value to the left operand. a &= b
|= OR and assign Performs bitwise OR and assigns this value to the left operand. a |= b
^= XOR and assign Performs bitwise XOR and assigns this value to the left operand. a ^= b
>>= Rightshift and assign Performs bitwise Rightshift and assign this value to the left operand. a >>= b
<<= Leftshift and assign Performs bitwise Leftshift and assign this value to the left operand. a <<= b
BINARY OPERATORS
5. Assignment Operators
// C program to illustrate the assignment operators
#include <stdio.h>
BINARY OPERATORS
int main()
{
int a = 25, b = 5;
5. Assignment Operators
printf("a = b: %d\n", a = b);
printf("a += b: %d\n", a += b);
printf("a -= b: %d\n", a -= b);
printf("a *= b: %d\n", a *= b);
printf("a /= b: %d\n", a /= b);
printf("a %%= b: %d\n", a %= b);
printf("a &= b: %d\n", a &= b);
printf("a |= b: %d\n", a |= b);
printf("a >>= b: %d\n", a >>= b);
printf("a <<= b: %d\n", a <<= b);
return 0;
}
TERNARY OPERATORS
Operators that work on three operands
• Conditional Operator ( ? : ) a shorthand for an if-else
statement and is useful for simple conditional expressions
Expression1 is the condition to be evaluated. If the condition(Expression1) is
True then we will execute and return the result of Expression2 otherwise if
the condition(Expression1) is false then we will execute and return the result
of Expression3.
Syntax: operand1 ? operand2 : operand3;
TERNARY OPERATORS
• Conditional Operator ( ? : ) #include <stdio.h>
int main() {
int a = 10, b = 20;
int max = (a > b) ? a : b;
Output:
printf ("The maximum value is %d\n", max);
The maximum value is 20
return 0;
}
TERNARY OPERATORS
• Conditional Operator ( ? : )
#include <stdio.h>
int main() {
int x = 5;
char *result = (x > 0) ? "Positive" : (x < 0) ? "Negative" : "Zero";
Output:
The number is Positive printf("The number is %s\n", result);
return 0;
}
OPERATORS: EXERCISES
Sample Result
1 || 0
5 && 10
12 ==12
1 != 2
1 && 2 && 0
1> 2
OPERATORS: EXERCISES
Sample Result
1 || 0 1
5 && 10 1
12 ==12 1
1 != 2 1
1 && 2 && 0 0
1> 2 0
OPERATOR PRECEDENCE AND ASSOCIATIVITY IN C
OPERATOR PRECEDENCE AND ASSOCIATIVITY IN C
OPERATOR PRECEDENCE AND ASSOCIATIVITY IN C
OPERATOR PRECEDENCE AND ASSOCIATIVITY IN C
Exercises:
• a = 4 + 2 * 5; what is the value of a?
• b = (22-4)*2-6; what is the value of b?
• c = 22-4*2-6; what is the value of c?
• d = 22-4*(2-6); what is the value of d?
Answer: a=14, b=30, c=8, d=38
SUMMARY
We have learnt;
- We use operators as symbols to perform operations in C programming language.
- There are three main types: unary, binary and ternary based on the number of operators used.
- The binary operators are arithmetic, relational, logical, bitwise, and assignment operators.
- Logical, relational and conditional operators return a boolean value (true (1) or false (0))
- = is used for assignment, == is used for comparison
- Prefix and postfix operators change the value first or later
- The precedence in the operators are basically, parantheses, brackets, suffixes, prefixes, multiply/divide,
plus/minus, assignment
NEXT WEEK
Basic i/o functions
REFERENCES
1. [Link]
2. [Link]
language/
3. [Link]
4. [Link]
5. Vatansever, F. (2017). Algoritma Geliştirme ve Programlamaya Giriş. Ankara:
Seçkin Yayınevi.