PPS Module No. 2
PPS Module No. 2
- 2
Fundamentals Of C-Programming
Structure Of C-Programming -
• #include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
Key Components of C-Program :
• (#include<stdio.h>) – Includes external files like libraries (in this case , stdio.h for
input/output functions.
• Main Function – (int main()) – The entry point of every C – Program. The program starts
execution from here. The int before main specifies that the function will return an
integer value, usually 0 to indicate successful execution.
• Statements : inside the main function , statements are written , such as variable
declarations, function calls, and other operations.
Execution Of a Program
2. Compilation – the source code is converted into object code by the compiler.
3. Linking – All object files and libraries are combined to create the final executable.
1. Syntax Errors : Mistakes in the code structure , such as missing semicolons, wrong
function calls, or incorrect operators.
2. Runtime Errors : Errors that occur during execution , such as division by zero, or
accessing invalid memory.
E.g. - int a = 5, b = 3;
• Character Set in C –
• Letters : a to z , A to Z
• Digits : 0 to 9
1. Identifiers : Names used to identify variables , functions , arrays, etc. They must start with
a letter (Uppercase or Lowercase) or an underscore, followed by letters , digits or
underscores. Identifiers are case-sensitive. E.g. int num;
2. Keywords : Reserved words in C that have special meanings and cannot be used as
identifiers.
Tokens –
1. Tokens : The smallest units in a program. C programs are made up of tokens, such as :
Data Types in C :
• C has several basic data types, each used to store different kinds of data. Some common data
types are: int: Integer type, used for whole numbers.
• double: Double-precision floating-point type, used for more accurate decimal numbers.
Additionally , C allows modifiers like short , long , signed, unsigned to modify the basic data
types :
• An enumerated data type (enum) is user-defined type that consists of a set of named
integer constants. E.g. - enum day {Sunday, Monday, Tuesday, Wednesday, Thursday,
Friday, Saturday};
• E.g. Integer literal = 100 , floating-point literal = 3.14 , Character Literal : ‘a’ , String
Literal : ‘Hello’
• Constants : Values that cannot change during the execution of the program. Constants
can be defined using the ‘const’ keyword or #define.
• C uses standard input and output functions for reading and writing data.
• Comments in C
• Comments are used to explain parts of the code. C supports two types of comments :
• Single-line Comment - // is used for comments that only span one line.
• Multi-Line Comment - /* comment */ is used for longer comments that span multiple lines.
• Control Structures in C : Control structures are used to control the flow of execution
in the progra,. The primary control structures are :
e.g. –
} else {
}
• Operators in C :
• Operators in C are special symbols that perform operations on variables and values. They help in
performing mathematical computations, logical operations, bit manipulations, and data handling.
1) Arithmetic Operators
2) Relational(Comparison) Operators
3) Logical Operators
4) Bitwise Operators
5) Assignment Operators
6) Increment/Decrement Oeprator
#include <stdio.h>
int main() {
int a = 10, b = 5;
return 0;
}
1) Relational (Comparison) Operators :
• Used to compare values and return a Boolean result ( 1 for true , 0 for true)
Operator Symbol Description Example(a=1 Result
0,b=5)
Equal to == Checks if two a==b 0
values are equal
or not
Not Equal to != Checks if two a!=b 1
values are not
equal
Greater Than > Checks if left a>b 1
operand is
greater
Less Than < Checks if left a<b 0
operand is
smaller
Greater than >= Checks if left a>=b 1
equal to operand is
greater or equal
Less than equal <= Checks if left a<=b 0
1) Logical Operators :
• E.g.
#include <stdio.h>
int main() {
int a = 10, b = 5;
return 0;
}
1) Typecasting in C:
• Typecasting is the process of converting one data type into another. C provides two
types of typecasting : 1) Implicit Typecasting (Automatic Conversion) 2) Explicit
Typecasting (Manual Conversion)
1) Implicit Typecasting :
• Happens automatically when a smaller data type is promoted to a larger data type.
#include <stdio.h>
int main() {
return 0; }
2) Explicit Typecasting :
• Requires the programmer to manually convert a variable from one type to another
using (type)
e.g.
#include <stdio.h>
int main() {
float a = 10.5;
return 0;
}
2) Global and Local Variable Declaration :
1) Global variables :
// Global variable
void display() {
int main() {
display();
return 0; }
2) Local variables :
void display() {
int main() {
display();
return 0; }
• Data Input and Output :
• The printf() function is used to display text and variable values on the console.
• Syntax : putchar(character);
e.g. - #include <stdio.h>
int main() {
char ch = 'A';
putchar(ch);
return 0;
int main() {
char ch;
return 0; }
• Syntax- puts(string);
puts(str);
return 0; }
• The gets() function reads a full line of text (including spaces) until the user presses
enter.
• Syntax- puts(string);
e.g. #include <stdio.h>
int main() {
char name[50];
gets(name);
return 0; }
1. Fundamentals Of The Graphics Design (Graphics functions in C)
1. Putpixel()
• This is very simple function , it just displays a pixel specified by co-ordinate location.
• Syntax : void line (int x1, int y1, int x2, int y2);
• E.g. line(20,20,30,30)
3. Rectangle()
• This function is used to draw a rectangle. Co-ordinates of left top and right bottom
corner is required to draw the rectangle.
• Syntax : void rectangle(int left, int top , int right, int bottom);
• E.g. rectangle(10,10,30,30);
3. Bar() – ( Same as Rectangle)
• Syntax : void bar(int left, int top , int right, int bottom);
• E.g. bar(10,10,30,30);
3. circle() –
• Circle function is used to draw a circle with center(x,y) and third parameter specifies
the radius of the circle.
• E.g. – circle(3,3,50);
* Difference Between Web Design & Graphic Design :
Designing functional and user-friendly Creating visually appealing content for print
websites. and digital media.
Layout , UI/UX, responsiveness, interactivity. Branding , visual storytelling
Websites , web applications , mobile Logos, brochures, posters, social media posts,
interfaces advertisement.
HTML/CS , Wordpress, Sketch Adobe photoshop , illustrator, InDesign.