C Operators
C Operators
and identifiers
Presented by: Lochan raj dahal
▪ All the words used in C program which have fixed predefined
meaning and whose meanings can’t be changed by the users are
termed as Keywords. There are fixed number of keywords in C
programming language and every keyword serves as a building
block for program statements.
Note: Since C is a case sensitive programming language all the keywords must be written in lowercase.
▪ In the real world, when a new baby is born a name is given.
Similarly, in C program when a new variable, function or an
array is declared a particular name is given to them which is
called an identifier. For example
C
Programmin int apple;
External ▪ program1.c
Variable #include "myfile.h"
#include <stdio.h>
void printValue(){
printf("Global variable: %d", x);
}
▪ A data type specifies the type of data that a variable can store
such as integer, floating, character, etc.
There are the following data types in C language.
Datatypes in
C
programmin
g Types Data Types
Array: with a 0 index for the first entry. The size of the
array is fixed at declaration time and cannot be
changed during program execution. The array
components are placed in adjacent memory regions.
Here is an example of declaring and utilizing an array:
#include <stdio.h>
int main() {
int numbers[5]; // Declares an integer array with a size
of 5 elements
// Assign values to the array elements
numbers[0] = 10;
numbers[1] = 20;
numbers[2] = 30;
numbers[3] = 40;
Array: numbers[4] = 50;
▪ You can have incorrect access and change the value of variable using
pointers by specifying the memory address of the variable. Pointers are
commonly used in tasks such as function pointers, data structures,
and dynamic memory allocation.
int main() {
// Declare a variable of type struct Person
struct Person person1;
Structure: // Assign values to the structure members
strcpy(person1.name, "John Doe");
person1.age = 30;
person1.height = 1.8;
return 0; Output:
}
Integer Value: 42
Float Value: 3.14
▪ A set of named constants or enumerators that represent a
collection of connected values can be defined in C using
the enumeration data type (enum). Enumerations give you
the means to give names that make sense to a group of integral
values, which makes your code easier to read and maintain.
Enumeration ▪ Here is an example of how to define and use an enumeration
Data Type in C:
#include <stdio.h>
// Define an enumeration for days of the week
enum DaysOfWeek {
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
};
Enumeration int main() {
// Declare a variable of type enum DaysOfWeek
Data Type enum DaysOfWeek today;
▪ Example:
Void Data
Type void printHello() { printf("Hello, world!\n"); }
▪ Function Parameters:
▪ The parameter void can be used to indicate that a function accepts no
arguments.
▪ Example:
void processInput(void) { /* Function logic */ }
▪ Any address can be stored in a pointer of type void*, making it a
universal pointer. It offers a method for working with pointers to
ambiguous or atypical types.
▪ Example:
void* dataPtr;
Pointers: ▪ The void data type is helpful for defining functions that don't accept any
arguments when working with generic pointers or when you wish to
signal that a function doesn't return a value. It is significant to note that
while void* can be used to build generic pointers, void itself cannot be
declared as a variable type.
Here is a sample of code that shows how to utilize void in various situations:
#include <stdio.h>
// Function with void return type
void printHello() {
printf("Hello, world!\n");
}
// Function with void parameter
void processInput(void) {
printf("Processing input...\n");
}
int main() {
Pointers: // Calling a void function
printHello();