0% found this document useful (0 votes)
22 views24 pages

Programing Fundamentals Full semester Notes

The document provides comprehensive notes on programming fundamentals, covering key concepts such as programming definitions, software types, and the roles of assemblers, compilers, and interpreters. It details the C programming language, including its character set, data types, variable naming rules, arithmetic instructions, and control structures like loops and conditionals. Additionally, it includes examples of C syntax, input/output functions, and the structure of a basic C program.

Uploaded by

rindgm524
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views24 pages

Programing Fundamentals Full semester Notes

The document provides comprehensive notes on programming fundamentals, covering key concepts such as programming definitions, software types, and the roles of assemblers, compilers, and interpreters. It details the C programming language, including its character set, data types, variable naming rules, arithmetic instructions, and control structures like loops and conditionals. Additionally, it includes examples of C syntax, input/output functions, and the structure of a basic C program.

Uploaded by

rindgm524
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

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

Applications system software computer


. Language
. And Translater

Microsoft Office

Typing software etc

OS Utilities Machine Language Assembly lang

(0,1-binory) High Level Languages

Linux , Windows DiskMount , Antivirus

Mac-OS , MS Dos Device Drive Forton , Pascol , cobal, c , c++ etc

Assembler , Interpreter , compiler

→Assembler , Interpreter and Compiler:

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”.

- Unlike compilers, interpreters do not generate a separate object code file.

- Interpreters execute the program directly, checking for errors as they go.

- Errors are reported immediately when encountered during execution.

- Examples of interpreted languages include Python, JavaScript, and Ruby.

→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

A-Z , a-z , 0-9, Constant , Variables , Keywords

/ , * , - , + etc Reserve Words

→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.

→Keywords in C are int , float , double , while etc.

→Programing Parts

• Data and instructions.


→Types of instructions:
1. Type declaration instructions
2. Arithmetic Instructions and Assignment operator
3. Input output instructions
4. Control instructions
(a)Sequence Instructions
(b)decision logic or conditional control instructions
(c)looping or inerratic control instructions
(d)Case Control Instructions

→Type Declaration Instructions :


It is Used To create and initialize variables

→Syntax

<DataType> <VariableNAme>[<constant>]

→Example For Integer :

Signed int x; OR int x = 12; OR int x , y=10;

→Example For character :

char ch = ‘A’; Or char ch = ‘a’;

→Example For Float;

flaot num = 1.53;


→Data types in “C” (32 Bit)

Primary / primitive datatypes secondary data types

Arrays

Pointers

Integer Real character structures

Signed int (2 bytes) float (4 bytes) signed char ( 1 bytes) Unions

can store -32768 to 32767 elements -1.2 × 10^-38 to 3.4 × 10^38 -128 to 1`27 Enum Etc

-2n-1 to 2n-1 -1 (n=bits)

Unsigned int (positive) Double unsigned char

Allocate 2 bytes memory 8 Bytes 1 byte

0 to 65535 -3.4e308 to 3.4e308 0 to 255

Signed long long

4 bytes 10 bytes

Unsigned long

4 bytes

→Rules For Naming Variable


1. Every variable name must start with an alphabet letter
2. A variable name can no contain any special symbol like (@ , % , $ etc) and
blank spaces ,except – or _ like(full-name)
3. A variable name consist of 1 to 255 letters however shorter and meaning
full names are preferred.
→Arithmetic instructions and assignment operator :
5+3
Operand Operand

Operator

Definition : Arithmetic instructions are used to perform arithmetic operations


There are 5 Basic arithmetic operator in “C”
1. Plus “+”
2. Minus “-:
3. Multiplication “*”
4. Division “\”
5. Modulor or Reminder

→Operator precedence rules in “C” :


• First parentheses ()
• Then multiplication division and modulor * , \ , %
• Then in final plus and minus - , +

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

“=” it used for assign data to variable


→Example
int A; here we declare variable
A = 16 ; here we are adding 16 to variable A
int B ; here we declare and other variable
B = A ; here we added A value which is (16) into to variable B
printf(“%d”, B); now it will output 16;
→Input Output Instructions :
→printf is the output function which is used to display output screen.
→scanf is the input function which is used to take input from user.

>>Syntax:
printf(“<format string>”[,<varaiblename>]);
→Example
#include<stdio.h>
void main(){
int i = 10;
printf("%d",i);
}

→Escape Sequence , format specifier and string constant


String Constant Escape Sequence Format specifier
printf(“HelloWorld”); printf(“Hello world\n”); printf(“%d”,i);
“” these double cotes \n is known as escape % before d is known as
known as string constant sequence format specifier

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.

o Common format specifiers include:

▪ %d for integers

▪ %f for floating-point numbers

▪ %c for characters

▪ %s for strings

▪ %p for pointers

o Example:

o int num = 42;

o printf("The answer is %d\n", num);


2. Escape Sequences:
o Escape sequences allow you to represent special characters inside string
literals.

o They start with a backslash (\) followed by a character.

o Common escape sequences include:

▪ \n for a newline

▪ \t for a tab

▪ \\ for a literal backslash

▪ \" for a double quote

o Example:

o printf("Hello, world!\n");

3. String Constants:
o String constants are sequences of characters enclosed in double quotes.

o Example:

o const char* message = "Hello, C!";

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

→Writing first C program


→Important points
• Every C program contain main Function
• If program does not return any value in will be void main
• If program return some integer values it will be int main
• Every program’s body after int main there will be { and end with }
• Every instruction in C should be end with ;
• In latest code editor we use header file but in old ide like turbo c does not require
any header file
• For adding header file in C we use #include<libraryname>
• In C there is stdin(standard input output ) library for using printf and scanf
functions in latest ide/ code editors like VS code and dev c++
• In old ide like turbo c we use clrscr(); for clearing screen and used getch() for
holding output screen.
• C is case sensitive language it means in C the two word with same spelling have
different meaning for example Hello and hello these both word have same
spelling but in c the Hello have H capital that’s why it will be deferent from Hello

→Sample program for printing hello world


#include<stdio.h>
void main(){
printf("Hello World");
}
→Remarks or Comments in C
Definition: comments are that type of code which will not we be read by complier at runtime
// use for comment out single line

/*use to comment paragraph */

→Sample Code Example


#include<stdio.h>
void main(){
//this is sample comment
printf("Hello World");
/*this is paragraph of
comment in c it will not be read by compiler at run time*/
}

→Scanf the input function


Syntax
Scanf(“<formatspecifier>”,&<variablename>);
→”&” is known as address operator

→Sample Program with dry run output method;

#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

Main backend Output screen


num1 num2 sum Enter Here Number : 10
And you entered number for example 10
10 Now it will store in num2 variable memory
location

→Dry Run Second step printing final output

Main backend Output screen


num1 num2 sum as sum = num1+num2 Enter Here Number : 10

10 10 20 The sum of 10 and 10 is 20

→ Decision logic or conditional control instructions


These statements allow you to control the flow of your program based on conditions.

1. if Statement:
o The simplest decision-making statement.

o It evaluates a condition and executes a block of code if the condition is true.

o Syntax:

o if (condition) {

o // Code to execute if condition is true

o }

o Example:

o int x = 10;

o if (x > 5) {

o printf("x is greater than 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 // Code to execute if condition is true


o } else {

o // Code to execute if condition is false

o }

o Example:

o int x = 3;

o if (x > 5) {

o printf("x is greater than 5");

o } else {

o printf("x is not greater than 5");

o }

3. else-if :

o Used for multiple conditions.

o Syntax:

o if (condition1) {

o // Code for condition1

o } else if (condition2) {

o // Code for condition2

o } else {

o // Code if none of the conditions match

o }

o Example:

o int x = 7;

o if (x > 10) {

o printf("x is greater than 10");

o } else if (x > 5) {

o printf("x is greater than 5 but not 10");

o } else {

o printf("x is less than or equal to 5");

o }

→Code Screen
→switch Statement:
o Used for multi-way branching based on a value.

o Syntax:

o switch (expression) {

o case value1:

o // Code for value1

o break;

o case value2:

o // Code for value2

o break;

o // ...

o default:

o // Code if no case matches

→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.

→Types of loops in “C”


1. For loop
2. While loop
3. Do while loop

→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.

→while() loop: while is a protest conditional looping instructions , in which a


given boolen expression is tested prior to executing the body of loop if the given
condition is true the body of loop it’s execution and repetition is continued until
the given condition become false.

→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.

→One dimensional Array (1D Array):


➢ How To Declare one dimensional array
→Syntax
<datatype> <variablename><[Size]>
→Example :
int number[20];

➢ How to initialize one dimensional array;


int number[5] = {1 , 2 , 3 , 4 ,5}; OR char name[5] ={‘w’ , ‘a’ , ‘j’ , ‘i’ , ‘d’};
→Index in array start from 0 ;
→Example;
char name[5] ={‘w’ , ‘a’ , ‘j’ , ‘i’ , ‘d’};

Index Element
0 w
1 a
2 j
3 i
4 d

➢ How to print one dimensional array


1. Accessing individual array elements
→Example :
int num[5] = {12 , 23 ,34 , 13 , 56};
printf(“%d”,num[index number]);
printf(“%d , num[0]); →Output will be 12
if index is 0 then it will print 1st element.

→For store or replace element in array:


num[index number]= element;
num[0] = 12;
2. Accessing All elements of one dimensional array
Known as array traversal
We can access all or print all array elements using loop
→Example

→Output :

→1D Array Of String

→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

(b) How to initialize 2 D array


Int marks[5][4] = {1 , 32 , 54 , 53 } , {2 ,34 , 53 ,62 }, {3 ,53 ,53
,64} , {4, 34 , 63, 63} , {5 , 43 , 53 ,53};
→IN MEMORY
1 32 54 53
2 34 53 62
3 53 53 64
4 34 63 63
5 43 53 53

(c) How to Access 2D array


→Single element
Marks[arrayrow][arraycoloum];
→Example
Marks[3][2];
→output = 64
→traversal (all Elements)
Using nested loop

→Example

For(i=0;i<no of Rows;i++){
For(j=0;j<no of colums;j++){
Printf(“%d”,marks[i][j]):
}
Printf(“\n”);
}

→Strings Functions in “C” :


1.Strlen();
It is used to return the length of a string
→syntax
[<intvariable>] = strlen(<string>);

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;

7.strcmp(); It is used to compare string and it is case sensitive


If both strings are than it will return 0;
If are not equal It will return 1;
→syntax
stcmp(<stringfirst> , <stringsecond):

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

Predefined or user defined functions

Standard library functions

Example : strcpy() , getch(), exit()

Strlen() , pow() , sqet();

→Advantages of Functions
• Code reusability
• Modular approach
• Easy code management

→Preprocessor Directives
1. File inclusion #include
→syntax
#include<libraryname><.h>
#include<stdio.h>

2. Creating Constant/ Macros #define


→syntax
#define<name>{<constant>;<expression>}
#define area pi*(2*2)
→User Defined Function
• Declare Function Prototype
• Calling Function
• Function Defination

→Classification of functions as per prototype


1. Void function (void)
2. Void function (input)
3. Output function (void)
4. Ouput dunction(input)

→Important points about functions


➢ Conventionally a function in c can return maximum one value
➢ A “return” statement is used to return a value form a function in C
➢ More than one value in C can be received either using arrays or call by
reference / pointers.
→syntax
→declaration after header file void name();
→can be initialized at the declaration but it is better to initialize separately
after main() function

→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”}

→Access the struct


Using dot(.)
<struct var name> <dot><mem name>

I have not added written codes in these notes because


these are theory notes for definitions.

You might also like