Posts

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

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

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

CHAPTER 3 Conditional Instruction

Image
  What us conditional instruction in c language ? CONDITIONAL INSTRUCTION Sometimes we want to watch comedy videos on Youtube if the day is Sunday Sometimes we order junk food if it is our friend’s birthday in the hostel You might want to buy an umbrella if its raining and you have the money you order the meal if dal or your favorite bhindi is listed on the menu. All these are decisions which depend on a condition being met. In c language too, we must be able to execute instructions on a condition being met. learn c programming Ques1 :-What are decision making instructions in c? Decision Making Instructions in C if-else statement switch statement Ques 2 : -What is if-else statement in c ? if-else statement The syntax of an if-else statement in C look like: if (condition to be checked) { statement-if-condition- true; } else{ statement-if-condition-false; ] code example:- int a= 23; if (a>18){ printf(”you can drive\n”); } Note that else block is ...

Chapter 2: Instruction and operators

Image
                          Instruction and Operators  A  c program is a set  of instructions. just like a recepie-Which contains instructions to prepare a particular Dish. Types of instruction  1.Type declaration Instruction 2. Arithmetic Instruction 3. Control Instruction Type declaration Instruction int a; float b; Other varities: i nt i=10; int j=i ; int a=2 int ji=a+j-i ; float b=a+3 ; float =1.1***ERROR ! as we are trying to use before defining it *** int abcd ;  a=b=c=d=30 ;*** value of abcd will be 30 each*** Airtmetic Instruction  int i=(3*2) +1 "*" "+"             **** these are operators*** "3,2,1"               ***these are operands*** operands can be int /float etc. +,-,*,/ are arthmetic operators int b=2, c=3; intz; Z=b*c;              ***legal*** intZ; b*c=z;    ...

Chapter 1 "C programming"

Image
 Hello guys this is the first chapter of c programming , In this chapter we will learn about basics of c programming  ; Here we go to learn c language,                 Chapter 1 Variable, contest &keywords                   Variable :- A Variable is a container which stores a 'value' Like in kitchen we use containers storing rice ,Dal,Suger etc. Similarly, To that Variable in c Stores  Value of a constast . Example: A=3;      //a is assinged"3" b=4.7;    //b is assigned "4.7" c='A' ;    //c is assinged "a" Rules of naming variable in C :- 1. First character must be an alphabet or underscore(_). 2. No commas , blanks allowed  3.  No special symbol other than (_) allowed. 4. variable names are case sensitive  We Must create  meaningful variable names in our programs. This enhance raedabibly of our programs. Ques: What is variab...

My work in c programming

Hello  dear, I am sourabh Sangwan student of bca in second semester and learning c programming and also making notes and c programming projects