Posts

Showing posts from June, 2022

Chapter 7 Arrays

Image
Array An array is a collection of similar elements one variable ⇒ capable of storing multiple values Syntax The syntax of declaring an array looks like this. Int marks[90]; ⇒ Integer array char name[20]; ⇒ character array or strong float percentile[90]; ⇒ float array The values can now be assigned to marks array like this : marks [0] ⇒33; marks [1] ⇒12; NOTE; It is very important to note that the array index starts with 0 marks → 7,6,21,3,91,3,.,.,.,88,89 0 1 2 3 4 5 . . . 88 89 Total = 90 elements Accessing elements Elements of an array can be accessed using ; scanf(”%d”,&marks[0]); ⇒ Input first value printf(”%d”,marks[0]); ⇒ Output first value of the array Initialization of an array There are many other ways in which an array can be initialized. int cgpa [3] = {9,8,8} ⇒ Array can be initialized while declaration float marks[] = {33,40} Arrays in memory Consider this array; int arr [3]={1,2,3} ⇒ 1 integer =4bytes This wil

Chapter 6 Pointer

Image
                  Chapter 6 Pointer A pointer is a variable that stores the address of another VARIABLE i j 72                                  87994 address → 87994 ,87998 j is a pointer j points to i The address of “(&) ope1qreator The address of operator is used to obtain the address of the given variable If you refer to the diagram above &i⇒ 87994 &j ⇒87998 Format specifier for printing pointer address is ‘%u’ The value at address operator(*) The value at address or *operator is used to obtain the value present at a given memory address. It is denoted by * *(&i) =72 *(&j) =87994 How to declare a Pointer ? A pointer is declared using the following syntax int *j; ⇒ declare a variable j of typr int-pointer j=&i ⇒ Store address of in j Just like a pointer of type integer, We also have pointer to char, float etc. int* ch-ptr; → Pointer to integer char* ch-ptr; -. Pointer to character float* ch-ptr; → Pointe

Chapter 5 : Function and Recursion

Image
  Function and Recursion Sometimes our program gets bigger in size and its not possible for a programmer to track which piece of code is doing what function is a way to break our code into chunks so that it is possible for a programmer to reuse them. What is a Function? A function is a block of code that performs a particular task, A function can be reused by the programmer in a given program any number of time example and syntax of a function #include<stdio,h> void display () ——> function prototype int main(){ int a; display(); ———> function call return 0; } void display () { ———> function definition printf(”Hi i am display”); } Function prototype Function prototype Declaration  The function prototype is a way to tell the compiler about the function we are going to define in the program Here void indicates that the function returns nothing Function call Function call is a way to tell the compiler to execute the function body at the time the call

Chapter 4 Loop Control Instruction

Image
Why loops Sometimes we want our programs to execute a few sets of instructions over and over again for ex. printing 1 to 100, the first 100 even number, etc. Hence Loops make it easy for programmers to tell the computer that a given set of instructions must be executed repeatedly. Types of loops:- Primarily, there are three types of loops in C language: 1. While loop  2. do-while loop 3. for-loop We will look into this one by one while loop while(Condition is true) { //  code //code                                         =>  The block keeps executing as long as the condition is true } An example int i=0 while (i<10) printf ("The value of i is %d",i); i++; NOTE:  If the condition never becomes false, the while loop keeps getting executed. Such a Loop is known as an infinite loop. Increament and decreament operators i++ ----> i is decreased by 1. i--  -----> i is decreased by 1 printf ("--i - %d",--i);  This first documents i and then print it printf (&qu