Professional Documents
Culture Documents
LDP Unit-2 Material
LDP Unit-2 Material
1. Documentation
This section consists of the description of the program, the name of the
program, and the creation date and time of the program. It is specified at the start
of the program in the form of comments. Documentation can be represented as:
// description, name of the program, programmer name,
date, time etc.
/*
description, name of the program, programmer name,
date, time etc.
*/
2. Preprocessor Section
All the header files of the program will be declared in the Processor
section of the program. Header files help us to access other’s improved code into
our code. A copy of these multiple files is inserted into our program before the
process of compilation.
#include<stdio.h>
#include<math.h>
3. Definition
Preprocessors are the programs that process our source code before the
process of compilation. There are multiple steps which are involved in the writing
and execution of the program. Preprocessor directives start with the ‘#’ symbol.
The #define preprocessor is used to create a constant throughout the program.
Whenever this name is encountered by the compiler, it is replaced by the actual
piece of defined code.
Example:
#define long long ll
4. Global Declaration
5. Main() Function
Every C program must have a main function. The main() function of the
program is written in this section. Operations like declaration and execution are
performed inside the curly braces of the main program. The return type of the
main() function can be int as well as void too. void() main tells the compiler that
the program will not return any value. The int main() tells the compiler that the
program will return an integer value.
Example:
void main()
Created by : Kinjal Mehta
Silver Oak Group of Institutes
Silver Oak College of Computer Application
or
int main()
6. Sub Programs
● Executing C program
C program file is compiled and executed, the compiler generates some files with
the same name as that of the C program file but with different extensions.Below image
shows the compilation process with the files created at each step of the compilation
process:
The file extension ".c" must be used when saving any file that includes a C
programme. This is required in order for the compiler to understand that the file is a C
programme.
Suppose a program file is named, first.c. The file first.c is called the source file
which keeps the code of the program. Now, when we compile the file, the C compiler
Token in C
TOKEN is the smallest unit in a ‘C’ program. It is each and every word and
punctuation that you come across in your C program. The compiler breaks a
program into the smallest possible units (Tokens) and proceeds to the various
Created by : Kinjal Mehta
Silver Oak Group of Institutes
Silver Oak College of Computer Application
stages of the compilation. C Token is divided into six different types, viz,
Keywords, Operators, Strings, Constants, Special Characters, and Identifiers.
● Data Types
Each variable in C has an associated data type. Each data type
requires different amounts of memory and has some specific operations
which can be performed over it. It specifies the type of data that the
variable can store like integer, character, floating, double, etc. The data
type is a collection of data with values having fixed values, meaning as
well as its characteristics.
Integer Types
Character Types
#include <stdio.h>
Created by : Kinjal Mehta
Silver Oak Group of Institutes
Silver Oak College of Computer Application
int main()
{
char a = 'a';
char c;
printf("Value of a: %c\n", a);
a++;
printf("Value of a after increment is: %c\n", a);
// c is assigned ASCII values
// which corresponds to the
// character 'c'
// a-->97 b-->98 c-->99
// here c will be printed
c = 99;
printf("Value of c: %c", c);
return 0;
}
Floating-Point Types
○ The name of a variable should not be any reserved keywords like int,
float, str, char, etc.
Datatype variable_name;
int a, b, d;
int _c;
char letter;
float z ;
Constants
1. Integer constant
An integer constant is a whole number and can be large without including
any decimal points. For example, 0, 1, 2, 123, 5767, 05, 0X23, 0xFFF, etc.
2. Float constant
The float constants are the part of an integer constant that containing a
decimal point, fractional form and exponential form.
Here are some example of floating point constants:
0.5, 35.05, 2.3e6, 3.52f or 3.52F, PI = 3.14, etc.
3. Character Constants
It is a single character constant enclosed within a single quotation mark
(like 'a', 'A'), called a character constants. There are some valid constants
as: 'g', 'D', ' ', '#'.
4. String Constant
It is the character set of string constants that are enclosed in a double
quote. The character may be letters, numbers, special symbols and some
blank space. Furthermore, a string constant contains zero, one or more
continuous character in double quotation marks. For example, "Hello
Friends", "Computer", "5987", " " , "A".
#include<stdio.h>
#include<conio.h>
#define PI 3.14
scanf("%d", &radius);
getch();
● Type Casting
Typecasting in C is the process of converting one data type to
another data type by the programmer using the casting operator during
program design.
In typecasting, the destination data type may be smaller than the
source data type when converting the data type to another data type, that’s
why it is also called narrowing conversion.
int x;
float y;
y = (float) x;
Types of Type Casting in C
C there are two major types to perform type casting
● Comments
int main(void)
{
// This is a single-line comment
printf("Welcome to GeeksforGeeks");
return 0;
}
/*
Created by : Kinjal Mehta
Silver Oak Group of Institutes
Silver Oak College of Computer Application
This comment contains some code which
will not be executed.
printf("Code enclosed in Comment");
*/
printf("Welcome to GeeksforGeeks");
return 0;
}