Programing Fundamentals Full semester Notes
Programing Fundamentals Full semester Notes
Program:
It is list or sequence of instructions that are given to the computer
to resolve a particular programs
Programing:
It is science and art of writing program
→Software
Microsoft Office
1. Assembler:
- An assembler translates programs written in assembly language into machine code (also known as object code).
- Assembly language is a “low-level programming language” that uses mnemonics (such as `ADD`, `MUL`, `MOV`, etc.)
to represent instructions.
- The output generated by the assembler is the machine code that the computer can understand.
- Assemblers serve as the first interface that allows communication between humans and machines.
2. Compiler:
- A compiler reads the complete source program written in a “high-level language” (e.g., C, C++, C#) as a whole and
translates it into an equivalent program in **machine language**.
- The compilation process involves several stages, including lexical analysis, syntax analysis, semantic analysis, and
code generation.
- If the source code is free of errors, the compiler produces object code successfully.
- Errors are specified at the end of compilation, along with line numbers.
- Once compiled, the object program can be executed multiple times without retranslation.
3. Interpreter:
- An interpreter translates a high-level language program into machine language “line by line”.
- Interpreters execute the program directly, checking for errors as they go.
→Origen Of C Language
The C programming language was developed in the early 1970s by American computer scientist
Dennis M. Ritchie at Bell Laboratories (formerly AT&T Bell Laboratories). Ritchie designed C to
be a general-purpose computer programming language that could efficiently map to machine
instructions while providing low-level access to memory. It was created as a successor to the
programming language B and was initially used to re-implement the Unix operating system
kernel. Over time, C has become one of the most widely used programming languages, with
compilers available for various computer architectures and operating systems12.
→C character Set
→Constant : Constant are Fixed values or data that can not be changed or modified during the
execution of program.
→Variables : These are named memory location that maybe assigned values which can be
modified or changed at runtime,
→Keywords : These are reserve words of programing language whose meaning is already
defined to the compiler or interpreter.
→Programing Parts
→Syntax
<DataType> <VariableNAme>[<constant>]
Arrays
Pointers
can store -32768 to 32767 elements -1.2 × 10^-38 to 3.4 × 10^38 -128 to 1`27 Enum Etc
4 bytes 10 bytes
Unsigned long
4 bytes
Operator
If theses thing comes two in one equation or the all division multiplication comes in on
equation then we have to resolve left to right one by one
>>Syntax:
printf(“<format string>”[,<varaiblename>]);
→Example
#include<stdio.h>
void main(){
int i = 10;
printf("%d",i);
}
1. Format Specifiers:
o Format specifiers are placeholders used in printf and scanf functions to format
input and output.
o They indicate the data type of the value being printed or read.
▪ %d for integers
▪ %c for characters
▪ %s for strings
▪ %p for pointers
o Example:
▪ \n for a newline
▪ \t for a tab
o Example:
o printf("Hello, world!\n");
3. String Constants:
o String constants are sequences of characters enclosed in double quotes.
o Example:
printf("%s\n", message);
→Explanation Chart
Program Output Explanation
printf(“Hello world”): Hello world Direct output hello world
on screen with printf
function
printf(“\nHello world”): Used escape sequence
Hello World \n for next line that’s why
it prints the hello world
on next line
printf(“Hello\tworld”): Hello World Used Escape sequence
\t for space between two
character
int n = 10; 10 Used format specifier
printf(“%d” , n): %d for printing number
→Important Chart
Format Specifier Explanation Escape sequence Explanation
%d %d for integer \n Used for next line
output/input
%f %f use for float \t Used for space
value output/input
%c %c used for \\ User for
character input / backslash
output
%u %u used for \” Used for double
unsigned int cote
%lu %lu used for
unsigned long
%lf %lf used for
double
%s %s used for
strings
#include<stdio.h>
#include<stdio.h>
void main(){
int num1=10, num2, sum;
printf("Enter Here Number : ");
scanf("%d", &num2);
sum = num1+num2;
printf("The sum of %d and %d is %d",num1 , num2 , sum);
}
→Screen output
→Dry Run first step allocating memory
1. if Statement:
o The simplest decision-making statement.
o Syntax:
o if (condition) {
o }
o Example:
o int x = 10;
o if (x > 5) {
o }
2. if-else Statement:
o Combines if with an alternative block of code to execute when the condition is
false.
o Syntax:
o if (condition) {
o }
o Example:
o int x = 3;
o if (x > 5) {
o } else {
o }
3. else-if :
o Syntax:
o if (condition1) {
o } else if (condition2) {
o } else {
o }
o Example:
o int x = 7;
o if (x > 10) {
o } else if (x > 5) {
o } else {
o }
→Code Screen
→switch Statement:
o Used for multi-way branching based on a value.
o Syntax:
o switch (expression) {
o case value1:
o break;
o case value2:
o break;
o // ...
o default:
→Nested If
If we use if condition in if condition is known as nested if
Example;
If(i<=10){
if(i==8){
Printf(“It is 8”):
}
→looping control instructions
→loop:It is the repeative peace or block of code that is given in the program while
looping is the mechanism or process of creating loops.
→For() loop:
It is the counter looping which is used to repeat a piece of block of code for
given number instruction
→syntax
For(<initialize counter>;<condition>;<increment/decreasement>;){
//body
}
Example Program:
#include<stdio.h>
int main(){
int i;
for(i=1;i<=10;i++){
printf("Hello World\n");
}
return 0;
}
→Output Screen:
→Concept Of Break And Continue :
→Break:
It is used to Exit from Loop or switch case .
→Continue :
It is used to transfer program control at the beginning of the
loop.
→Syntax:
while(<condition>){
//body
Increment and decrement
}
→Program Example :
#include<stdio.h>
void main(){
int i=1;
while(i<=10){
printf("Hello World\n");
i++;
}
}
→Output
→do while():
It is post test conditional looping instructions I which given
boolen expression is tested after excuting body of loop at least once after
executing first iteration of loop , if loop exits otherwise it continues repeating.
→Syntax :
do{
// body
Increment or decrement
}while(condition);
→Program Example :
#include<stdio.h>
void main(){
int i=1;
do{
printf("Hello World\n");
i++;
}while(i<=10);
}
→Output screen
→if you want to make infinite loop just enter “1” in condition in “C” “1” means
true and “0” means false.
→getch() and getche():
getch and getche both are single character input
functions which are used to store user’s given character form keyboard into a
character variable at runtime
getch does not display (echo) the given character on screen while it is preside
form keyboard however getche() shows or displays the character on screen;
→syntax
[<variable name>]=getch() / getche();
→getchar(); in latest ide we use getchar instead of getche but you can use
getch in lates ide by using conio.h library
→Exit():
it is use to forcefully terminate “C” program
→goto:
It is unconditional branching conditions instruction which used to
transfer program control at a specified label within a program.
→Syntax
<label>: // C statement
Goto<label>
Example:
#include<stdio.h>
void main(){
int num;
begin:
printf("\nEnter Here Number : ");
scanf("%d" , &num);
if(num<=10){
goto begin;
}
else printf("Thanks");
}
→Arrays :
An array is the collection or group of homogenous (similar) data
elements , In arrays all elements are stored in continues memory locations.
Index Element
0 w
1 a
2 j
3 i
4 d
→Output :
→Declare
char Name[5];
→initialize
Name[5] = {‘w’ , ‘a’ , ‘j’,’i’ , ‘d’} OR Name[5]={“Wajid”}
→Accessing
→single element
printf(“%c”,Name[indexnumber]);
→all elements
Using loop for(i=0;i<5;i++){
printf(“%c”, Name[i]);
}
→Two dimensional Arry (2D)
(a) How To declare 2D array
<datatype> <variable name><[no of rows][no of colums]
→Example
Int marks[5][4];
→Memory chart
0 0 0 1 0 2 0 3
1 0 1 1 1 2 1 3
2 0 2 1 2 2 2 3
3 0 3 1 3 2 3 3
4 0 4 1 4 2 4 3
→Example
For(i=0;i<no of Rows;i++){
For(j=0;j<no of colums;j++){
Printf(“%d”,marks[i][j]):
}
Printf(“\n”);
}
2.strcat();
It is used to append (concatenate) source string at end of target
string.
→Syntax
Strcat(<targetstring>,<sourcestring>);
→Example :
Char firstname[20] = “Wajid”;
Char lastname[20] = “Mirjat”;
Strcat(firstname , lastname);
3.gets();
It is used to store user given input into a string variable in runtime.
→Syntax
gets(variable name);
4.puts();
It is used to output string or display string output
→Syntax puts(string variable name)
5.strcpy();
It is used to copy source string into target string
→syntax
strcpy(<target string>,<source string>);
6.strrev();
It is used to reverse a given string
→Example
Char name[] = “Wajid”;
Puts(strrev(name)); →Output = dijaW;
8.stricmp();
It is same as stcmp but it is not case sensitive and syntax is same
as stricmp .
→gotoxy();
It is old function not used in latest new ides it is functions used to
move curser of screen.
→Function
A function is a self-contained named block of statement that perform some
particular task.
→Types Of Function
→Advantages of Functions
• Code reusability
• Modular approach
• Easy code management
→Preprocessor Directives
1. File inclusion #include
→syntax
#include<libraryname><.h>
#include<stdio.h>
→Pointers :
Pointers are special type of variable tat can store memory of
tother variable .
& = address of operator
“ * “ = value at address operator
→Structures :
Structures are group or collection of heterogenous (dis
similar) data element .
→Syntax
Struct <varablenme>{
//body
}
→declaration
Struct employee{
Eid;
Ename;
}
→ initialize
Struct employee{32 , “ahmed”}