MODULE 1 : BRIEF INTRODUCTION
KLIC C PROGRAMMING
PROGRAMMING LANGUAGE
As we know, to communicate with a person, we need a specific language, similarly to communicate with computers,
programmers also need a language is called Programming language.
Language is a mode of communication that is used to share ideas, opinions with each other. For example, if we
want to teach someone, we need a language that is understandable by both communicators.
A programming language is a computer language that is used by programmers (developers) to
communicate with computers. It is a set of instructions written in any specific language ( C, C++, Java, Python)
to perform a specific task.
A programming language is mainly used to develop desktop applications, websites, and mobile applications.
TYPES OF PROGRAMMING LANGUAGE
Low-level programming language High-level programming language
• Low-level language is machine-dependent (0s • High-level programming language (HLL) is designed
and 1s) programming language. for developing user-friendly software programs
and websites.
• The processor runs low- level programs directly
without the need of a compiler or interpreter, so the • This programming language requires a compiler or
programs written in low-level language can be run interpreter to translate the program into machine
very fast. language (execute the program).
ABOUT C PROGRAMMING
C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972.
It is a very popular language, despite being old. The main reason for its popularity is because it is a fundamental
language in the field of computer science.
C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
C is very versatile; it can be used in both applications and technologies.
To start using C, you need two things:
I. A text editor, like Notepad, to write C code
II. A compiler, like GCC, to translate the C code into a language that the computer will understand
SYNTAX OF C PROGRAM
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
C VARIABLES
Variables are containers for storing data values, like numbers and characters.
In C, there are different types of variables (defined with different keywords), for example:
I. int - stores integers (whole numbers), without decimals, such as 123 or -123
II. float - stores floating point numbers, with decimals, such as 19.99 or -19.99
III. char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
C VARIABLE SYNTAX
The syntax to declare a variable in C specifies the name and the type of the variable.
data_type variable_name = value;
// defining single variable
or
data_type variable_name1, variable_name2;
// defining multiple variable
data_type : Type of data that a variable can store.
variable_name : Name of the variable given by the user.
Value : value assigned to the variable by the user
RULES FOR DECLARING VARIABLES
C Variable Names :
Names can contain letters, digits and underscores.
Names must begin with a letter or an underscore (_)
Names are case sensitive ( myVar and myvar are different variables)
Names cannot contain whitespaces or special characters like !, #, %, etc.
Reserved words (such as int ) cannot be used as names.
DECLARING A VARIABLE
To create a variable, specify the type and assign it a value:
type variableName = value;
Where type is one of C types ( such as int , float , char)
variableName is the name of the variable ( such as x or myName)
The equal sign is used to assign a value to the variable .
Ex. Int num = 10;
You can also declare a variable without assigning the value, and assign the value later:
// Declare a variable
int myNum;
// Assign a value to the variable
myNum = 15;
EXAMPLE OF VARIABLES
• int age; • int 1stPlace = 5;
• float salary = 5000.75; • float average score = 78.5;
• char grade = 'A'; • char @symbol = '$’;
• double pi = 3.14159; • double 3.14 = pi;
• const int MAX_VALUE = 100; • const int MAX_VALUE;
DATA TYPES
HOMEWORK
1. What is a variable in C?
2. How do you declare a variable?
3. Can you change the value of a variable after it has
been declared?
4. Name two data types in C.
5. How do you initialize a variable?
6. Explain the purpose of the `const` keyword in C.
FORMAT SPECIFIER
Format specifiers in C are used to take inputs and
print the output of a type.
The symbol we use in every format specifier is %.
Format specifiers tell the compiler about the type of
data that must be given or input and the type of
data that must be printed on the screen.
C TOKENS
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.
C KEYWORDS
C language supports 32 keywords which are given below:
DATA TYPES
CONSTANTS IN C
A constant in C language is a value that remains constant throughout the program and cannot be changed during
program execution.
Constants in C can be of many types, including integer constants, character constants, floating point constants,
arithmetic constants, and array constants.
In other words, they are used in programs to represent constant values that will not change.
For example, if you're working on a program that requires a ‘Pi’ value, you can define ‘Pi’ as a constant so its
value doesn't change while the program is running.
1. Constants declaration comprises of the const keyword followed by the respective type. That is,
constants are declared using appropriate literals such as ‘const int’, ‘const float’, etc.
2. Constants must begin with an integer value when declared. For example, ‘const int number =
10’
3. A constant cannot be changed after it has been declared. Attempts to update the constant will
result in an error.
4. Constants can be defined globally, that is, they can be accessed by any part of the program. They
can also be accessed locally, that is, only by deriving from the number block they are defined in.
5. Constants can be defined using tags such as ‘#define PI 3.14159’, which is a prefix that defines
the constant ‘PI’ to have the value 3.14159.
#include <stdio.h>
const int MAX_VALUE = 100;
const float PI = 3.14;
int main() {
const int MIN_VALUE = 0;
printf("Max value: %d\n", MAX_VALUE);
printf("Pi: %.2f\n", PI);
printf("Min value: %d\n", MIN_VALUE);
return 0;
}