Hey guys welcome to my channel. In this video I will be covering complete unit 1 in C programming. Guys I have uploaded complete C language subject tutorials. I will provide link in description you can watch from there.
I also provided study material link in description you can download from there. If you are watching this video for the first time don't forget to like share and subscribe to my channel. Let's get started.
Guys these are the topics that I am going to cover in this video. Whatever the topics that I am going to cover in this video I provided all those topics in description. So before starting this video please check in description. At first I will explain components of computer, computer languages.
and what are translators and also I will explain what is memory and various types of memory and what are operating systems and various types of operating systems. At first I will explain components of computer. We also call this components of computer as functional units of computer.
Before that let me explain what is computer. Computer is an electronic device that takes input data from input devices and it stores and processes data and produce output. For example if you consider keyboard, keyboard is an input device because by using keyboard we can enter input.
So computer is an electronic device. that takes input data from input devices like keyboard and then it stores the data and process the data and produce output. Output is seen in output devices like monitor.
We can see output in monitor. So monitor is output device. You need to know difference between data and information.
Data is nothing but it is collection of unorganized facts and information means processed or organized data is known as information. In simple terms data means unorganized facts and whereas information means organized data. Components of computer is divided into two categories.
one is hardware and next one is software hardware is physical parts of computer like cpu monitor mouse keyboard which we can touch is known as hardware all these are the examples of hardware devices next what is software software provides instructions to computer that is it tells computer what to do and there are two types of softwares one is system software and next one is application software software which is designed for system is known as system software for example windows xp Windows 10, Linux all these are examples of system software because the software's are designed especially for system and software Which are designed for users is known as application software for example Photoshop, MS Office All these are examples of application software because the software's are designed for users for their personal use Hardware contains system software like Windows 10 and inside system software. We can install application software's like MS Office Photoshop so on and this application software are accessed by user. System software act as interface between hardware and application software and whereas application software act as interface between system software and user. Each and every computer follows five basic operations. First one is take input.
It is the process of entering data and instructions into computer. I already said before computer takes input by using input devices like keyboard. And next one is store data. Whatever the data that we entered, this data is stored in our computer so that we can access that data when required and this data is stored either in ram or hard disk. The fourth one is processing data.
Performing automatic and logical operations on data in order to convert this data into useful information is known as processing data. And fourth one is output information. The process of producing useful information or result to user and we can see this output by using output devices like monitor. Fifth one is control the workflow. The above four operations must be done in sequence manner.
and it is handled by computer. Computer system consists of three components. They are first one is input unit, second one is central processing unit that is CPU and third one is output unit. And the central processing unit contains three components. They are first one is control unit, next one is automatic and logical unit and third one is memory unit.
This is block diagram for components of computer. We also call this diagram as Von Neumann architecture. First one is input unit. This input unit contains input devices such as keyboard, mouse, so on.
By using this input devices we can enter input and this input unit establish connection between user and system. Next one is CPU. CPU is considered as brain of computer because each and every operation is controlled by CPU and all types of data processing operations are handled by CPU.
This CPU itself contains three components and the first one is control unit. The name itself says control unit. Control unit means whatever the instructions or operations that CPU receives All these operations are controlled by control unit.
Next one is arithmetic and logical unit. Data processing tasks are handled by arithmetic and logical unit. As I already said before, performing arithmetic and logical operations on data in order to convert them into useful information that is nothing but processing data. Data processing tasks such as performing arithmetic calculations and logical operations are handled by arithmetic and logical unit. And last one is memory unit.
Whatever the input that user provide to system, this input is stored in memory unit and as well as output is stored in memory unit for example if i give input like one plus two then this input one plus two is stored in memory unit and i will get output as 3 this result 3 is stored in this memory unit next i will explain types of memory memory is very important for each and every system because if we don't have memory in our system then we cannot perform even single task in our system so memory is very essential for each and every system computer system contains two types of memory one is primary memory and next one is secondary memory at first i will explain what is primary memory there are two types of primary memory one is random access memory and next one is read-only memory. At first I will explain what is RAM. RAM stands for random access memory. This RAM is temporary storage that is whatever the data that is present inside RAM once we shut down our system then all this data will be lost.
So we call this RAM as temporary storage. There are two types of RAM. One is static RAM and next one is dynamic RAM.
At first I will explain what is static RAM. Shortly we call this static RAM as SRAM. In static RAM data is present until we shut down our system and next one is dynamic RAM.
In dynamic RAM data is stored in our system very short time even though if we do not shut down our system within short time our data will be lost in dynamic RAM. This static RAM is very costly when compared to dynamic RAM and this static RAM consume more power when compared to dynamic RAM. Next I will explain ROM. ROM stands for read only memory.
This is permanent storage because even though we shut down our system then data will be present in our system. So we call this ROM as permanent storage. There are three types of ROM. First one is PROM where PROM stands for programmable read-only memory in programmable read-only memory once we copy any data in prom then we cannot delete that data and next one is ep rom where ep rom stands for erasable programmable read-only memory name itself says erasable means once we insert any data in ep-rom we can delete that data and then we can insert new data and next one is electrically erasable programmable read-only memory shortly we call it as eep-rom in electrically erasable programmable read-only memory we can delete data by using electric waves by using special electrical waves we can delete data within milliseconds in eep-rom Next I will explain secondary memory. We also call this secondary memory as external memory.
Example of secondary memory are CDs, DVDs, pen drives, floppy disks. All these are examples of secondary memory. Next I will explain computer languages.
Computer languages are classified into three types. First one is machine level language, second one is assembly language and third one is high level language. At first I will explain what is machine level language.
Language which is understandable only by machines is known as machine level language. We also call this machine level language as low level language. Generally this language is in the form of zeros and ones.
So this is not understandable by users. This language is understandable only by machines and this language was introduced in 1940s. In olden days that is in 1940s system understand only machine level language that is machine can understand only zeros and ones and second one is assembly language.
Language which uses some symbols in order to write program is known as assembly language. Generally this language uses symbols. So we call this language as symbolic language and this language was introduced in 1950s. Third one is high level language. Language which is understandable by users is known as high level language.
Generally this language is in the form of English language. Language which is understandable by users is known as high level language and language which is understandable by machines is known as machine level language or low level language. For the C program that I written, this C program is in high level language that is in English language.
So computer cannot understand this high level language. So in order to convert this high level language into machine understandable language that is into low level language we need translator. The name itself says translator that means it will translate high level language into low level language.
There are two types of translators one is compiler and next one is interpreter. In C we use compiler that means for example i open turbo c++ and i return program in turbo c++ and then i will click on alt f9 whenever you click on alt f9 that mean you are compiling your program whenever you click on alt f9 this compiler will convert this high level language program into low level language that is in the form of zeros and ones so this is use of compiler next one is interpreter interpreter also convert high level language into low level language we use this interpreter in java difference between compiler and interpreter is compiler will convert entire program into low level language at a time but whereas interpreter will take one line and then it will convert this line into low level language after compiling this line into low level language only after that it will go to next line and then again it will convert this line into low level language after that it will go to third line so on. I will explain what is operating system.
For example, if any user want to access any hardware components, then definitely you need one operating system in order to access those hardware components. So this operating system act as interface between user and hardware components. Example of operating systems are Windows 6p, Windows 10, Linux, all these are examples of operating system.
So if any user want to access hardware components, then definitely you need one operating system in order to access those hardware components. For example, if you want to access any software like MS office or Photoshop or notepad or any games then definitely you need one operating system in order to access those software. This diagram for example users want to access any software like system software or application software this both are present in operating system and this operating system is connected to hardware and this hardware contains CPU or RAM or any input and output devices this is diagram. These are some of the important functions of any operating systems. First one is memory management.
By using operating system, we can perform memory management and next we can also perform processor management, device management, file management and this operating system also provides security and this operating system is also used to control system performance. These are various functions provided by operating system. These are various types of operating systems.
At first I will explain what is batch operating system. The name itself says batch. Batch means group of people. For example if there are some users perform similar type of job then whatever the users that perform similar type of job is grouped into one batch. For example let us consider three users user1, user2 and user3.
These three users perform similar type of job. So these three users are grouped into one batch. In olden days users write program in punch cards for example these three users will write some programs in punch cards and then they will submit this punch cards to computer operator so that this computer operator will insert this punch cards into system so in batch operating system users cannot directly interact with computer they will just submit punch cards to computer operator and then this computer operator will insert this punch cards into this system and then he will perform his task this is known as batch operating system What is multitasking or time sharing operating system? For example, let us consider there are different users located in different places and these users want to access same computer at a time. All these users can access this single computer at a time by using internet and this is considered as time sharing operating system.
I will explain what is real-time operating system. This real-time operating systems will give response within short period of time. Military software system, space software system, all these are examples of real-time operating system.
If there is any crime or any bomb blast, then this military operating systems will give immediate response. And similarly, if there are any changes in space, then immediately we will get response by using space software systems. These both are examples of real-time operating system.
Next, what is mobile operating system? Operating system which is designed especially for mobile is known as mobile operating system. Example Android, iOS all these are examples of mobile operating systems because they are especially designed for mobiles.
Next I will explain what is network operating system. This network operating system runs on server. every software companies contains server and this server contains network operating system and this network operating system has capability to manage data manage users and also it will provide security and other networking functions this is use of network operating system next i will explain what is distributed operating system normally every computer contains only one cpu but whereas in distributed operating system It contains multiple processors.
Processor is nothing but we call CPU as processor. So distributed operating system uses different processors. So that these systems are very fast when compared to other systems. Next topic is numbering system concept in C programming. Numbering system is classified into four types.
First one is binary number system. Second one is octal number system. Third one is decimal number system and fourth one is hexadecimal number system. Let first I will explain what is binary number system. Binary number system is a system that is used to classify a number of variables.
digits. Binary number system contains two digits they are 0 and 1. Example 0 1 1 0 1 base 2 is an example of binary number system. We can also call this binary number system as base 2 number system.
This binary number system contains only two digits they are 0 and 1. I will give one more example 0 1 1 1 0 base 2. It is also an example of binary number system 1 1 1 base 2. We also call this binary number system as base 2 number system. Next one is octal number system. Octal mean 8. So octal number system contains total 8 digits from 0 to 7. We also call this octal number system as base 8 number system.
This is an example of octal number system. Octal number system contains numbers from 0 to 7. So it contains number from 0 to 7 that is 735. These numbers are in between 0 to 7. So we call it as octal number system. Here you need to write base 8. I will give one more example.
3, 5, 6, 7, base 8. Numbers are in between 0 and 7. So we call it as octal number system. Next I will explain decimal number system. Meaning of decimal is 10. So it contains 10 digits from 0 to 9. We also call this decimal number system as base 10 number system.
This is an example of decimal number system. Contains numbers from 0 to 9 and we represent decimal number system with base 10. I will give one more example of base 10 number system like 99i2 base 10 which should contains numbers from 0 to 9. Next I will explain what is hexadecimal number system. Hexa means 6 and deci means 10. Total it contains 16 digits.
So we also call this hexadecimal number system as base 16 number system. This hexadecimal number system contains numbers from 0 to 9. After that it contains alphabets like a b c d e f where a represent n. B represent 11, C mean 12, D mean 13, E mean 14 and F mean 15. Total it contains 16 digits from 0 to 15 where 0 to 9 are numbers and A, B, C, D, E, F are alphabets.
This is an example of hexadecimal number system FA319 base 16 where base 16 represent hexadecimal number system for example 1110. We call it as binary number system because it contains 0 and 1. So we call it as binary number system. For example 3 5 8 1. We call it as decimal number system because it contains numbers from 0 to 9. For example 1 1 1 7. We call it as octal number system because numbers are in between 0 and 7. A 10. We call it as hexadecimal number system because it contains alphabet A. For example if they give 7 3 5 base 10. actually 735 actually these numbers are in between 0 and 7 so actually it is octal number system but in question if they give like 735 base 10 then you need to consider this as decimal number system because here they given base 10 though numbers are in between 0 and 7 if they give base 10 then you need to consider it as a base 10 number system for example 125 base 10 this is decimal number i want to convert this decimal number 125 into binary octal and hexadecimal you I will explain this by using calc.
At first you need to click on mode. Here you can see options. Here you need to select base n. So click on 4. Here by default it will show decimal. Here you need to enter your number.
Here number is 125. So I am entering here 125. Place is equal to. Here you can see number 125. Now I want to convert this 125 into binary. Here you can see option binary. bin so click on it so this is result this is how we convert decimal number into binary so answer is don't count zeros count from one one is from here now so right here one one one one one zero one if i convert this decimal number into binary this is result if you want to convert this into octal just here you can see option octal here you can see octal just click on it So if you convert decimal number 125 into octal then you will get answer as 175. So if you convert this decimal number 125 into octal result is 175. If you want to convert this 125 into hexadecimal then just click here.
Here you can see hexadecimal button just click on it answer is 70. This is how we convert decimal number into binary octal and hexadecimal. For example I want to convert binary number into decimal, octal and hexadecimal. Let binary number be 101, 1, 1, 1, 0, 1. I want to convert this number into decimal, octal and hexadecimal.
So at first you need to click on mode. Here you can see option that is base n. So click on 4. Here by default it will show decimal, but I want to convert binary number into decimal.
So here you need to select binary. here you can see option binary click on it so now it will show binary enter binary number that is 10111 and press is equal to here you can see number 10111 now i want to convert this binary number into decimal here you can see option decimal so click on it so answer is 93 so similarly i want to convert this binary number into octal so just click on octal here you can see option octal click on it so answer is 135 if you want to convert this binary number into hexadecimal here you can see hexadecimal button just click on it answer is 5d this is how we convert a binary number into decimal octal and hexadecimal for example i want to convert octal number 125 into binary decimal and hexadecimal so here at first you need to click on mode and here select option 4 that is base in here by default you will see decimal but i want to convert octal number so here select octal here you can see option octal click on it and enter number that is 125 and press is equal to so now you can see your octal number 125 just click on binary in order to convert this octal number into binary so just click on binary this is answer that is guys don't count zeros count from one that is 1 0 1 0 1 0 1 and if you want to convert this octal number 125 into decimal then just click decimal button you can see here click on it. So answer is 85 and if you want to convert this octal number into hexadecimal then just click on hexadecimal button you can see here click on it answer is 55. This is how we convert octal number into binary decimal and hexadecimal.
Next I will explain how to convert hexadecimal value a into decimal binary and octal. If I click on mode select option 4 that is base n here by default you will see decimal here you need to select hexadecimal because you want to convert hexadecimal number so click on hexadecimal here you can see alphabets a b c d e f where a mean 10 b mean 11 c mean 12 d mean 13 e mean 14 and f mean 15 here you can see alphabets from a to f here i want to convert this hexadecimal number a here you can see click on it and press is equal to so here you can see hexadecimal number a Now I want to convert this hexadecimal number A into decimal. So just click on decimal. Answer is 10. And if you want to convert this hexadecimal number into binary, then just click on binary.
Answer is 1010. And if you want to convert this into octal, then just click on octal. Here you can see octal. Click on it. Answer is 12. This is how we convert hexadecimal number into decimal, binary and octal. Next topic is introduction to C programming.
In this video, I will cover complete C basics. What are header files? What is main function?
Difference between int main and void main? Printf, scanf? What are variables, data types, and format specifiers? In this video, I will cover all these topics.
C is a programming language developed by Dennis Ritchie in the year 1972. The C language was developed by Dennis Ritchie. is one of the famous computer scientists. He developed C language in the year 1972 at AT&T Bell Laboratories. This AT&T Bell Laboratories are one of the famous laboratories located in USA where AT stands for American telephone and T stands for telegraph. This is history of C language.
At first in the year 1960 Algol 60 was introduced. After that updated version of this Algol 60 is CPL where CPL stands for combined programming language. It was introduced in the year 1963. Updated version of this CPL is BCPL where BCPL stands for Basic Combined Programming Language. It was introduced in the year 1967. Updated version of this BCPL is B language.
It was introduced in the year 1969. After that updated version of this B language is C language. It was introduced in the year 1972. This is history of C language. BCPL was developed by Martin Richards and B language was developed by K.L.
Thomas. and C language was developed by Dennis Rich. We can also call this C language as system programming language because by using C language we can develop various kinds of system softwares like operating system.
Most of the Unix and Linux operating system is developed by using C language. C is case sensitive language. For example, if you consider small a and capital A both are not same. It will read capital A and small a differently. This is meaning of case sensitive language.
C is also a robust language because by using C language we can develop complex programs. So we call this C language as robust language. We can also call this C language as middle level language because C has capability to understand both low level language and as well as high level language.
So we call this C language as middle level language. C also supports portability. Portability means for example if I write program in one system, if I write C program in one system simply I can copy this program and I can run this program in another system. This is meaning of portability. You can write program once.
and you can copy that program into various systems. Now I will explain first C program by using print function. At first you need to write hash include htdio.h.
You need to write hash include open angle bracket htdio.h where htdio.h stands for standard input output header file. Meaning of printf and scanf is present in htdio.h header file. So for each and every program we use printf.
So by default you need to write hash include std o dot h starting. After that you need to write void main. We call it as main function.
Whatever the code that you write inside this main function this code will be executed. So right here void main open curly bracket and inside this you need to write printf where printf stands for print function open bracket open double quotation. Whatever the text that you write inside this double quotations it will be displayed on my output screen for example I want to print text that is I am Nagendra so inside double quotations I am writing I am Nagendra and close double quotations and close bracket Definitely you need to use semicolon otherwise it will display error. So definitely you need to use semicolon and close curly bracket.
Whenever you execute this program you will get output as I am Nagendra. Some students will directly write like this main printf and they will write some text. But in exam you should not write like this.
Definitely you need to write hash include stdo.h because meaning of printf is present in stdo.h header file. For each and every program we use printf. So by default you need to write hash include html.h after that you need to write void min meaning of void is nothing.
So there is no need of returning anything. For example same program same program in place of void if I write here int where int is nothing but this is integer data type. So void is nothing but no return type. I am not returning anything meaning of void is nothing there is no need of returning anything.
But whenever you write here int main, definitely you need to return something. So here you need to write return 0. Here I give an integer type. So you need to write here 0. 0 is integer type or you can also give here 1 and definitely give here semicolon.
This is difference between void main and int main. Whenever you write here void main, there is no need of returning anything. But whenever you write here int main, whenever you give here return type as int. Definitely you need to return any integer value. So I return here return 0. This is with no return type.
Void min no return type. Int is with return type. In exam they may ask difference between void min and int min. There are two common escape sequences that we use in C.
On that first one is slash t where slash t stands for horizontal tab. And next one is slash n where n stands for new line. I will explain use of this escape sequences by using program.
Guys this is program here I want to print numbers from 1 to 8. So I want to print numbers from 1 to 8. So I return here printf where printf stands for print function. After that open bracket and take double quotations. Inside double quotations you can write numbers. So I return here numbers from 1 to 8. By writing this program I will get output as this is my output. I will get output as 1 2 3 4 5 6 7. but I don't want output like this I want to get output like this 1 in next line 2 next line 3 next line 4 of that next line 5 so on.
So if you want to get output like this you need to use escape sequences that is slash n where slash n stands for new line. So I want to print numbers from 1 to 5 so I return here printf open bracket inside double quotations I am writing 1 slash n 2 slash n 3 slash n and so on 4 3 slash n 4 slash n close double quotations close bracket and give semicolon. Whenever you write like this you will get output as 1 where slash n stands for new length. So 2 will be printed on next line after the slash n 3 will be printed on next line after that 4. This is my output.
For example, I want to print how are you? So, I am writing here printf double quotations how slash n r slash n u. Whenever you execute this program, you will get output as how slash n mean next n after again slash n that mean this is my output. This is use of slash n.
Next, I will explain use of slash t where slash t stands for horizontal tab. For example, I want to print output like this one. After some gap, I need to get 2 and after some gap, I need to get.
Here at first I am writing 1 slash t where slash t stands for horizontal tab. Whenever you click on tab, how much space that you will get that much space you will get by using slash t. Similarly, 2 slash t 3 close double quotations, close bracket and give semicolon. Whenever you execute this program, you will get output as 1 slash t mean tab.
Whenever you click on tab. how much space that you will get that much space you will get here after 2 slash t 3 this is my output where slash n and slash t are two common escape sequences that we use next i will explain what is use of clr scr function where clr scr stands for clear screen clr scr function will remove previous programs output and then it will display only present program output for example here i written two programs here at first i want to print how are you So I return this program. Whenever I execute this program, I will get output as how are you. After writing this program, I return another program. I want to print btech.
so i written here printf btech whenever you write this program you will get both present program output and as well as previous program output but i don't want previous program output i want only present program output that is i want to print only btech for that purpose you need to use clr scr function so here just you need to write clr scr open bracket close bracket definitely you need to give semicolon though you write like this you will get error Whenever you write CLR ACR meaning of the CLR ACR is present in conio.h header file. So you need to write here hash include open angle bracket CONIO.h. Where CONIO.h stands for console input output header file.
Meaning of the CLR ACR is present in conio.h header file. So definitely you need to write here hash include conio.h. Whenever you execute this program then you will get out. output as BTEC.
So CLRSL function is used to remove previous program's output. This C program which I written in order to get this output name Nagendra and in next line rule number 25 in next line place Hyderabad. This is output which I want. So for that purpose at first I took printf and inside double quotations I written name Nagendra and here I given slash n whenever you give slash n next statement will be printed on next line.
So I given here slash n. Definitely you need to give slash n. Inside double quotations should not give slash n outside double quotations it will display error. After that again I took printf rule number 25. So in next line I will get output as rule number 25 and again I took printf and I even place Hyderabad.
Whenever you write this code you will get output as name Nagendra rule number 25 and place Hyderabad or you can also write like this by taking single printf you can write name Nagendra slash n rule number 25 slash n place Hyderabad. By taking single printf also you can write this program. Instead of taking three printf functions you can also take single printf function and inside this printf function you can write like this. First I will explain variables and data types.
Guys these two topics are very very important. If you don't understand these two topics then you will not understand entire C program. So listen this topic carefully. First I will explain. what are variables variables are used to store data it is nothing but variables are used to store any values like for example int a equal to 10 where this int is data type and a is variable variables are used to store values this 10 is value this value 10 is stored in variable a so this is use of variables this 10 is value 10 20 100 all these are integer types so we use data type int so for integer values we need to use data type int so here i'm using data type int and i variable name as a and this variable a will store value 10. This is use of variable.
Variable is used to store data or you can also say value. Its value can be changed and reused many times. We can also change this value and we can also use this value multiple number of times. There are some rules which we need to follow before declaring a variable and the first rule is a variable can have alphabets and underscore. We must start variable name with alphabet or you can also start variable name with underscore.
This is an example here I written int a equal to 10. This a is alphabet. We can start declaring variable with an alphabet or you can also start declaring variable with an underscore. This is an example here I written int underscore a equal to 10. You can also declare like this. Second rule is we cannot start variable name with number. For example here I written int 10 equal to 10. This 10 is number.
So you should never start variable with number. Whenever you write like this you will get error. You can write like this int a 10 equal to 10. equal to 10. You can write like this because as per rule we must start declaring variable with an alphabet. So here I am starting variable with an alphabet or you can also start with underscore and third rule is no white space is allowed. You should not give space in between variable name.
For example here I written int a given variable name as number n u m. You can write like this int number equal to 10. You can write like this but you should not give space in between variable name. Here I written int n space um equal to 10. Whenever you declare like this you will get error.
So you should not give space in between variable name. Next I will explain data types in C. Along with data types I will also cover water format specifiers.
There are three data types in C. First one is primary data type. Second one is derived data type and third one is user different data type.
Primary data type contains integer data type, character data type and float data type. Guys in unit 1 I will cover only this primary data type. Here I am taking variable name as a. I am assigning value as 10. This 10 is integer data type. For example if you want to assign any integer values to a variable then you need to use data type.
type int 10 20 1000 100 all these are integer values so you need to use data type int whenever you use data type int you need to use format specifier percentage d you need to remember this and similarly for example if you want to assign any floating point values to a variable for example b equal to 10.25 point represent floating point value. So whenever you want to assign any floating point values to a variable, then you need to use data type float. For example, 10.5, 25.25, 100.1, all these are floating point values. So whenever you want to use any floating point values, then you need to use data type float.
Whenever you use float data type, you need to use format specifier percentage if here you need to give float. For example, if you want to assign any single character. to a variable like c equal to a.
This a is character. So whenever you want to assign any character like c, a, d so on then you need to use data type character. Shortly we call it as char. You need to use this data type char.
and whenever you use character data type you need to use format specifier percentage c. Now I will explain c program so that you can clearly understand what is use of this variables data types and format specifiers. Now I want to store one integer value that is 10. So here I am taking data type as int and I am taking variable name as a and I am giving value of a as 10 where this 10 is integer data type where this 10 is integer value.
So I took here data type int. Now I want to print this value 10 for that purpose I need to write printf as I already said before for integer values you need to use format specifier percentage d. So in double quotations you need to write percentage d close double quotations comma value 10 is present in variable a.
So you need to give here a close bracket semicolon close curly bracket. Whenever you execute this program then you will get output as 10 because integer value which is present in variable a will be generated as output. So I will get output as 10. For example I want to store one float value that is 10.5 for that purpose I need to write float I am giving variable name as a and I am giving value as 10.25 semicolon printf printf function is used to generate output so I am taking here printf in double quotations for float you need to use format specifier percentage f so I am taking here percentage f flows double quotations comma this 10.25 is present in variable a so I am taking here a semicolon whenever you execute this program then you will get output as 10.25 because float value which is present in variable a will be generated as output so i'll get output as 10.25 similarly i want to store character so guys you need to remember one thing character data type is used to store only single character that is it can store only single alphabet it cannot store multiple alphabets i want to store one character value that is character i'm giving variable name as a and i am giving value as c and definitely you need to include this in single quotations Otherwise, it will display error. So, take single quotations for this C semicolon printf. For character, you need to use percentage C.
So, close double quotations comma. This C is present in variable A. So, I am taking here A. Close this semicolon. Whenever you execute this program, then you will get output as C.
I will explain C program in order to generate output 10, 20, 30. Here, I need to store three values in three variables. So, I am taking three variables that is int A equal to 10. I already given variable name a. So I cannot take this variable name a again. Again I am taking another variable name that is int b equal to 20 and int c equal to 30. I want to print three values 10, 20, 30. So for that purpose I need to take three variables. So I took three variables as a, b, c.
Now I want to print these three values as my output. So I am taking a printf percentage d. because this 10 is integer value so I'm taking a percentage d 10 will be printed on first line and 20 will be printed on second line so I need to use here slash n and next percentage d and next percentage d slash n total there are three integer values so I need to take three format specifiers that is percentage d close double quotations comma a comma b comma c because 10 is present in variable a 20 in variable b and 13 variable c so I took three format specifiers %d slash n %d slash n %d double quotations comma this %d is for variable a and this %d is for variable b and this %d is for variable c.
So I took here a comma b comma c close bracket semicolon. Whenever you execute this program then you will get output as 10 20 30. Guys this 10 20 30 this three are of similar data type that is int. So instead of writing like this you can also write like this int a equal to 10 comma b equal to 20 comma c equal to 30 semicolon.
Instead of taking three data types for three variables you can also take single data type because all these are with similar data type. So I took here single data type for example I want to get output as 1 20 10.5 and d. I want to get this output for that purpose I will write program this 1 and 20 both are integer values.
So I took here data type int I'm showing this value 1 in variable a so I'm taking here a equal to 1 comma b equal to 20 this 20 is stored in variable b and this 10.5 is float data type this 10.5 is float value so I need to take here float data type float already I took variable a b I'm taking another variable name that is c equal to 10 point semicolon and this d is character so I'm taking a data type char and you can take any variable name I'm taking variable name as f f equal to d and you need to give this d in single quotation semicolon. Now I want to print this value. So I need to take a printf. This a is integer type.
So I took here percentage d for a and next slash n. Next 20 is present in variable b. This variable b is integer data type.
So again I need to take percentage d slash n. This is for b and next 10.5 is present in variable c. This variable c is flow type.
So, I need to take here percentage f slash n comma this is for c. Last one is d. d is present in variable f and this variable f is character data type.
So, I need to take here percentage c comma f close with semicolon. Whenever you execute this program then you will get output as 1, 20, 10.5 and d. This is my output. Next I will explain what is use of scanf function. I will explain this scanf function with an example.
Let us consider one example. Here I am taking data type int and variable name as a. This variable a will store value 10. So in order to print this output I need to write printf 10 is integer type.
So here I need to use percentage d comma this 10 is present in a. So whenever you execute this program you will get output as 10. Int a equal to 10 we call this as variable initialization because we given value to this variable a. So we call it as variable initialization.
Instead of directly assigning value to a variable by using scanf function you can assign values after executing a program. I will give an example so that you can clearly understand. Here I am not initializing value I just declared int a and I did not assign any value to it so we call it as variable declaration. You can assign value to this variable by using scanf function.
So I am taking a scanf by using scanf function you can assign value to this variable a is a is integer type so i am taking here percentage d comma for scanf you need to use and a whenever you write this line of code you can assign value to this variable a after executing a program meaning of this is i can assign integer value and this value is stored in address a where and represent address next time writing printf next time writing printf my output is percentage d comma a semicolon Whenever you execute this program, it will show blank screen. Here you can give any value. For example, I want to assign value 10. So, just I will enter 10. Whenever you enter value 10, then you will get output as my output is 10 because I given here value 10. This is use of scanf.
By using scanf, you can assign value to a variable after executing a program. I will give another example. Guys, this is another program. Here I took int a. because I want to store one integer value so I took here int a and similarly I want to store one float value so I took here float b I want to assign value to this variable a and variable b after executing a program I can do this by using scanf so I written here scanf percentage d because this a is integer type so I am using here percentage d and this b is float data type so I am using here percentage f comma and a comma and b so whenever I write this line of code I can assign value to this variable a and variable b after executing a program so whenever i execute program i can enter value that is 10 which is stored in address a and next 10.5 which is stored in address b and by using printf i will get output so i will get output as 10 10.5 by using scanf i can enter values after executing a program and printer function is used to display output so i will get output as 10 and 10.5 next topic is how to create compile and execute a program and also i will explain software development life cycle and various types of errors in c at first i will explain how to create a program for example i want to create one c program so in order to create c program at first you need to open text editor for example if you consider turbo c turbo c is an example of text editor so at first you need to open turbo c in turbo c you need to write your program after writing your program you need to save your program with dot c extension here i'm saving my program with name program.c after creating program next step is compiling program whatever the c program that you written the c program is in high level language that is in english like language so in order to convert this program into machine understandable language you need compiler whenever you click on alt f9 then compiler will convert this program into machine understandable language that is into zeros and ones at the time object file will be created after compiling program next step is linking program now your program is linked to header file htdio.h this process is known as linking after linking your program with header files then executable file will be created now your program.c file is converted into executable file that is program.exe where exe stands for executable file so whenever you click on alt f9 both compiling and linking will be done whenever executable file is created if you click on ctrl f9 then you can execute your program after executing your program in order to display output you need to click on alt f5 whenever you click on alt f5 then you will get your output this is how we create compile and execute your program next i will explain software development lifecycle we also call this software development lifecycle as application development lifecycle or program development lifecycle before starting this you need to know some basics at first you need to know who are clients person who give project to software company is known as client for example example i want to design one college website so i went to software company and i asked them to design one college website so i am considered as client because i am giving project to software company so i am considered as client next you need to know who are software engineers person who do coding to our software is known as software engineer and person who creates flowchart or algorithm is known as software designer person who perform testing in order to find errors in our software is known as testing engineer what testing engineer will do is whatever the code that software engineer written, testing engineer will test this code in order to find errors in software this is duty of testing engineer.
these are four basics that you need to remember totally there are six stages in software development life cycle. on that first stage is analysis for example client given project to this software company in order to design one college website how much time and how much cost required in order to complete this project is known as analysis in this we need to identify time how much time that the software required to complete and how much cost it will take and what are the programming language that we required in order to complete this project all these are identified in analysis phase after analysis next phase is designing after detailed analysis of project software designers will design flowchart and algorithm for this project after designing flowchart and algorithm for this project next step is implementation this is third stage in implementation phase software engineers will write software code for this project after creating software code for this project then software engineers will submit this code to testing engineers in order to identify errors present in software for example if there are any errors present in the software then this testing engineers will submit this code back to software engineers so again software engineers will correct that code and again they will submit that code back to testing engineer example if there are no errors present in this project then in release phase we will submit project to client last step is maintenance maintenance is nothing but updating that software time to time these are six stages in software development life cycle next i will explain programming errors in c any false that occurs in program which makes behavior of program abnormal is known as programming error we also call this programming error as bugs or false or you can also call it as mistakes even experienced developers can also make this error totally there are five types of errors in c on that first one is syntax error any error made in syntax is known as syntax error for example actually in int i should be small but instead of taking i as small letter if i take i as capital letter then it is considered as syntax error because because data type should not start with capital letter so instead of taking small letter if i take capital i then it is considered as syntax error and we need to declare variables with data type like actually we need to write like int a equal to 10 if i write just like a equal to 10 without writing data type then it is also considered as syntax error next one is runtime error actually runtime error is nothing but whenever you compile your program that is whenever you click on alt f9 then it will not display any error but after executing your program that is at runtime it will display error like for example if i write here int a equal to 2 by 0 if we divide any number by 0 then result will be undefined so whenever you write like int a equal to 2 by 0 it will not display any error during compilation but after executing your program you will not get output because if we divide any number by 0 then result will be undefined so i will not get any output this is known as runtime error third one is linker error actually in main function you need to write m as small letter but instead of taking m as small if you write here m capital then it is considered as linker error and fourth one is logical error in logical error during compile and runtime It will not display any error but it will display wrong output. For example, I took value of a as 10 value of b as 20 and I return c equal to a plus b.
Now this c contains result. So now I need to write printf %d comma c because c contains result. So I need to print c but instead of printing c, if I write here %d comma a, now I will get output as 10. which is wrong answer mainly beginners will perform such kind of logical errors in logical error we will get undesired output it is error free but incorrect output this is known as logical error and last one is semantic error whatever the statements that we written in our c program if these statements are not understandable by compiler then it is considered as semantic error these are five types of errors in c programming next topic is operators in c i will explain what is an operator An operator is a symbol that tells compiler to perform specific mathematical or logical operations.
By using operator we can perform mathematical or logical operations. For example, if you consider a plus b where this a and b are operands and this place is operator. This place symbol is used to perform addition that is nothing but mathematical operation.
C language is rich in built in operators and provides following types of operations. of operators. Built-in operators are nothing but meaning of this operators are already present in header file.
So we call it as built-in operators. These are various types of built-in operators supported by C. On that first one is increment and decrement operator. At first I will explain what is increment and decrement operator. Increment operator will increment value by 1. For example here I took variable as a and I given value of a as 10. We denote increment operator with place place symbol.
So here I am using increment operator for variable a, plus plus a is equal to 11. I will get output as 11 because increment operator will increment value by 1. So 10 plus 1 that is 11. So I will get output as 11 for increment operator. Similarly for decrement operator, decrement operator will decrement value by 1. For example here I took variable name as a and I given value as 10. Now I want to use decrement operator. Here I written minus minus a, where minus minus represent decrement operator.
By writing minus minus a I will get output as 9 because decrement operator will decrement value by 1. So here 10 minus 1 that is 9 I will get output as 9 and we denote decrement operator with minus minus symbol. Increment operator is further classified into two types one is pre-increment and next one is post-increment. If you use increment operator before variable then we call it as pre-increment and if you use increment operator after variable then we call it as post-increment. where a represent pre increment and a represent post increment. Similarly, a represent pre decrement and a represent post decrement.
Now I will explain what is pre increment, pre decrement and what is post increment and post decrement by using programs. Now I will explain C program for pre increment and pre decrement. At first I will explain C program for pre increment. Here I took variable name as a and I given value as 10. This 10 is integer type.
So here I written data type as integer. Now I took printf and inside printf I written %d because for integers we use %d comma plus plus a where plus plus a represent pre increment. Pre the name itself says pre increment mean at first it will increment and then it will generate output. So by writing this program I will get output as 11. Similarly, I will explain program for pre decrement. Here I written int a equal to 10 and here I written printf inside printf I written.
%d comma minus minus a where this minus minus a represent pre-decrement. Pre-decrement mean it will decrement value by 1 and then it will generate output. So here I will get output as 9. This is program for pre-increment and pre-decrement.
Next I will explain program for post-increment and post-decrement. This is same program which I written before for pre-increment and pre-decrement. Here I written int a equal to 10 and after that I written printf %d comma a plus plus where a plus plus represent post-increment. Post mean after, pre mean before whereas in pre increment at first it will increment value and then it will generate output but whereas in post increment by writing this program I will get output as 10. I will not get output as 11 I will get output as 10. Meaning of this a++ is at first it will print same value after that it will increment value. So by writing this program I will get output as 10 and similarly again if I write printf %d comma a I will get output as 11. because meaning of this post increment is at first it will print the same value after that next time it will increment value so by writing this program at first I will get output as 10 next time it will increment value so I will get output as 11 similarly for post decrement meaning of this post decrement is at first it will print that same value and next time it will decrement value so again I need to write printf percentage d comma a by writing this program I will get output as 10 after that next time i'll get output as 9 this is a programs for post increment and post decrement next i will explain arithmetic operators arithmetic operators are used to perform automatic calculations like for example addition multiplication subtraction totally there are five arithmetic operators on that first one is addition we use symbol place and next subtraction we use symbol minus and next the symbol is for multiplication we call it as asterisk next division and last one is modulus it is considered two variables one variable name is a and another variable name is b.
a holds value 10 and b holds value 20. We can call this a and b as operands. First arithmetic operator is addition. We use symbol plus. Addition is used to add two operands where we call this a and b as operands.
This addition is used to add two operands that is a plus b. Value of a is 10 and value of b is 20 that is 30. I will get output as 30. Similarly, next arithmetic operator is subtraction. We use symbol minus that is a minus b. I will get output as 10 minus 20 that is minus 10. I will get output as minus 10. Next multiplication a asterisk b that is 10 into 20 that is 200. Next one is division. Division that is b by a.
Value of b is 20 and value of a is 10. So, I will get output as 2 by 1 that is 2. Last one is modulus. Modulus will provide remainder as output. For example, here I want to divide value of a by b if we divide value of a with b that is 10 divided by 20 10 to the 20 remainder is 0 modulus will provide remainder as output so here i will get output as 0 these are 5 arithmetic operators in c i will explain c program for these arithmetic operators this is c program for arithmetic operators here i took three variables where variable a contains value 10 and variable b contains value 20 and variable c will store result at first i want to perform addition so here i written c equal to a plus b value of a is 10 and value of b is 20 so i'll get result as 30 and this 30 will be stored in variable c so now i need to print variable c so i return here printf addition is percentage d comma c by writing this i will get output as addition is 30 and similarly next i want to perform subtraction so i return here c equal to a minus b now again I need to write printf subtraction is %d,c.
Here you need to write variable c because this variable c will contains result in place of c if you write here a or b then it will print value 10 which is wrong answer. So here you need to write %d,c. Next I want to perform multiplication here I return c equal to a asterisk b for writing this I will get output as multiplication is 10 into 20 that is 200 next I return c equal to a by b and after that I return printf division is percentage d comma c a by b that is 10 by 20 that is 1 by 2 I will get output as 0.5 similarly last one is c equal to a modulus b I already said before modulus will provide remainder as output.
So here I will get output as mod of c is 0. This is c program for various arithmetic operators. Next I will explain relational operators. Relational operators are used to identify relational between various operands.
These are various types of relational operators in c. First one is equal to, next one is not equal to, greater than, less than, greater than or equal to and less than or equal to. all these are relational operators in C.
Let us consider two operands where a holds value 10 and b holds value 20. At first I will explain what is use of is equal to operator. Is equal to operator is used to check whether value of operand a is equal to value of operand b or not. If value of a is equal to value of b then this condition is true.
This is how we represent is equal to operator that is a double equal to b and similarly not equal to. not equal to operator is used to check whether two operands are equal or not if they both are not equal then condition is true here value of A is 10 and value of B is 20 so A is not equal to B this condition is not satisfied and similarly here value of A is 10 and value of B is 20 so A is not equal to B this condition is satisfied so this condition is true next greater than symbol this is how we represent greater than symbol that is a greater than b value of a is 10 and value of b is 20. 10 is not greater than b. So, this condition is not satisfied.
If value of a is greater than b, then condition will be true. In this condition is false. Next, less than operator.
This is how we represent less than operator that is a less than b. Value of a is 10 and value of b is 20. 10 is less than 20. Condition is satisfied. So, in this condition is true.
Next one is greater than or equal to. This is how we represent greater than or equal to that is a greater than or equal to b. here value of a is 10 and value of b is 20 this condition is not satisfied because value of a is not greater than b value of a is less than or equal to b similarly last one is less than or equal to this is how we represent less than or equal to here value of a is 10 and value of b is 20 this 10 is less than or equal to b condition is satisfied for example if value of a is 10 and value of b also 10 even though condition is satisfied because here we have written less than or equal to so if value is less than or equal to this condition will be satisfied. Now I will extend C program for various relational operators. First relational operator is is equal to here at first I written a equal to 10 this 10 is integer type.
So here I written data type as int and value of a is 10 and value of b is also 10. Here I given condition that is if value of a is equal to b then I should get output as value of a is equal to b. This is condition which I given here value of a is 10 and value of b is also 10. So this condition is satisfied. I will get output as value of a is equal to b.
Similarly next I will explain c program for less than operator. Here I written a equal to 10 b equal to 20. If a value is less than b then I should get output as value of a is less than b. Here value of a is 10 and value of b is 20. This 10 is less than 20 so I will get output as value of a is less than b.
For example if I give value of a as 30 and value of b as 20. This 30 is not less than b. This 30 is greater than b. So here I will not get any output. If condition is not satisfied then I will not get any output. This is C program for various type of relational operators.
Next I will explain various types of assignment operators is equal to plus is equal to minus is equal to multiplication is equal to and division is equal to. After arithmetic operators you need to place is equal to that's it. First one is is equal to.
This is example. C equal to A plus B. This is an example of this assignment operator is equal to. Next operator is plus equal to.
This is an example of place is equal to operator. That is C plus is equal to A. Meaning of this.
c plus is equal to a is nothing but c equal to c plus a this is meaning similarly c minus equal to a meaning of this is c equal to c minus a c multiplication is equal to a meaning of this is c equal to c into a c division is equal to a meaning of this is C equal to C by A. This is meaning of this operator. Now I will explain C program for assignment operator.
This is an example of assignment operator. Here I took three variables where variable A holds value 10, variable B holds value 20 and where variable C holds result. Here I am using assignment operator that is is equal to.
I written here C equal to A plus B. This C contains result. So I need to print C by using printf addition is percentage D comma C. By writing this program I will get output as 30. This is C program for assignment operator. We represent assignment operator with is equal to symbol and these are various types of assignment operator supported by C.
Whenever assignment operator question comes in exam then you need to write this table and as well as program. Next I will explain bitwise operators. These are various types of bitwise operators.
On that first one is and second one is or. third one is not fourth one is left shift fifth one is right shift and at last sixth one is xor these are various types of bitwise operators guys you need to remember this table for bitwise and bitwise or and bitwise xor at first i will explain bitwise and for bitwise and if both values are one then result will be one else result will be zero and next for bitwise R. For bitwise R if both values are 0 then result will be 0 else result will be 1. This is for bitwise R.
Next for bitwise XR. For bitwise XR if both values are 0 then result is 0 and if both values are 1 result is 0 else if one value is 0 and one value is 1 result is 1. This is for bitwise XR. You need to remember this table.
Now I will give example for bitwise AND. Let us consider two numbers. One number is 7 and another number is 4. Now you need to convert this 7 and 4 into binary that is into zeros and ones. If you convert this 7 into binary then you will get value as 0 1 1 1 and similarly if you convert this 4 into binary then you will get value as 0 1 0 0. Now you need to compare this both bits.
Now we are performing bitwise AND for this. For bitwise AND if both values are 1. result will be 1 else result is 0. So compare this both 1 and 0 from last 1 and 0 that mean value is 0 next 1 and 0 value is 0 and for 1 and 1 value is 1 and for 0 0 value is 0. After performing bitwise and for 7 and 4 we got result as 0 1 0 0. Now you need to convert this 0 1 0 0 into decimal. If you convert this 0 1 0 0 into decimal then you will get value as 4. This is how we perform bitwise AND operation for two numbers. Similarly, we will perform bitwise OR operation for bitwise OR if both values are 0 then result will be 0 else result is 1. Now we will perform bitwise OR for number 7 and number 4. If you convert this 7 into binary then you will get value as 0 1 1 1 and if you convert this 4 into binary you will get value as 0 1 0 0. Now we need to compare this both that is 1 and 0 for bitwise or if value is 1 and 0 then result is 1 similarly for 1 and 0 result is 1 and similarly for 1 and 1 result is 1 and for 0 0 result is 0 if you perform bitwise or operation for this 7 and 4 then you got result as 0 1 1 1 if you convert this 0 1 1 1 into decimal then you will get value as 7 this is how we perform bitwise or operation guys this is c program for bitwise and operator i took two numbers one number is 7 and one number is 4. these both are integers so i took here data type as int after that now i am performing bitwise and operation so here i written percentage d comma a and b where and represent bitwise and operator so i written here a and b by writing this program i will get output as 4. Guys, I took the same example for this program. I will get output as 4. Guys, for bitwise OR operator, just in place of AND, you need to take OR.
If you take A bitwise OR and B, then you will get output as 7. Same as previous example. This is C program for bitwise AND and bitwise OR operators. Guys, now I will give table for bitwise NOT operator.
This is table for bitwise NOT operator. Here 0 is represented as 1. and 1 is represented as 0 that is just opposite this is table for bitwise not operator for example let us consider any number that is 7 if you convert this 7 into binary then you will get value as 0 1 1 1 now i want to perform bitwise not operation for number 7 0 is represented as 1 and 1 is represented as 0 so 1 is represented as 0 1 as 0 1 as 0 and 0 as 1 1 0 0 0 if you convert this binary number into decimal then you will get value as 8 this is an example for bitwise not operation Next I will explain logical operators. Totally there are three types of logical operators. And that first one is logical AND, second one is logical OR and third one is logical NOT. These are three types of logical operators.
where single and represent bitwise and and where double and represent logical and you need to remember this difference at first i will explain what is use of this logical and guys you need to remember this table guys i already explained this table in bitwise and operator where single and represent bitwise and where double and represent logical and guys you need to remember this where one represent true and zero represent false for logical and if both conditions are true then result will be true else result will be false that mean if both conditions are true only then i will get output this is for logical and i will give one example so that you can clearly understand what is this logical and operator this is an example here i took a value as phi this phi is integer so i took here data type as int and here i am giving condition that is if a value is greater than 0 and where this double and represent logical and operator if a value is greater than 0 logical and a value is less than 10 then I should get this output if both conditions are true then I will get this output that is condition true here I given value as 5 this 5 is greater than 0 condition is true because 5 is greater than 0 and similarly next condition is a value is less than 10 this 5 is less than 10 this condition is also true so if both conditions are true only then I will get output now I will get output as condition true for example if I give here value as 15 this 15 is greater than 0 this condition is true but this 15 is not less than 10. 15 is greater than 10. So this condition is false. If any single condition is false, then I will not get output. Here I will not get any output because a value is 15. 15 is not less than 10. 15 is greater than 10. So I will not get any output.
This is logical and operator. Next I will explain logical or operator. For logical or operator, if both conditions are false, then I will not get any output.
If single condition is true, then I will get output. If any single condition is true, then I will get output. only if both conditions are false then I will not get any output I will give an example so that you can clearly understand what is this logical R operator guys same example here just in place of logical and you need to write logical R that's it just in place of logical and write logical R for logical R if any single condition is true then I will get output here I given value as 15 15 is greater than 0 this condition is true but 15 is not less than 10 15 is greater than 10 so this condition is false if any single condition is true then i will get output so now i will get output as condition true this is logical or operator whenever logical operator question comes in exam then write this table for both logical and logical or and then give these examples guys we also call this ternary operator as conditional operator because based on the condition output will be generated this is syntax of ternary operator at first you need to write condition after that you need to give question mark symbol where question mark represent ternary operator at first you need to write condition question mark statement one colon statement 2 at last semicolon meaning of this is if this condition is true then this statement will be exeuted else this statement will be exeuted.
So this ternary operator is same as if else statement if condition is true then one statement will be exeuted if condition is false then else statement will be exeuted. So if condition is true statement 1 will be exeuted if this condition is false then statement 2 will be exeuted. I will give one program so that you can clearly understand what is this ternary operator.
This is C program for ternary operator. Here I took variable name as age and I given value as 20 and now I am giving condition that is if age is greater than 18 then I should get output as major else I need to get output as minor. Here I given age as 20. 20 is greater than 18 condition is true then I will get output as major.
For example in place of 20 if I give here 5, 5 is not greater than 18. Phi is less than 18. So I will get output as minor. So this is same like if else statement. If condition is true this statement will be executed else next statement will be executed.
This is C program for ternary operator. For increment and decrement operator we use only one operand for example a plus plus or a minus minus. Here we use only one operand.
So we call this increment and decrement operator as unary operator. and for arithmetic relational logical bitwise and assignment operators we use two operands for example a plus b where this a and b are two operands. So we call arithmetic relational logical bitwise and assignment operators as binary operator where by mean two. Next topic is what are conditional statements. We also call this conditional statements as decision making statements.
So conditional statements are used to make decision based on the conditions. Conditional statements are classified into five types. First one is if statement, next one is if else, third one is else if, fourth one is switch statement and fifth one is nested if. I will explain each of them in detail. At first I will explain what is if statement.
If statement exude block of code only if particular condition is true. If condition is false then whatever the statements that are present inside if will not be executed. I will give an example so that you can clearly understand what is if statement.
This is syntax of if statement. At first you need to write if and inside brackets you need to give any condition. Open curly bracket. and inside curly bracket you can write some statements. Only if this condition is true then these statements will be executed.
For example this condition is false then the statements will not be executed. I will give one program. First I written hash include htdo dot h after that I written int main open curly bracket here I written int a equal to 10. I given value of a as 10. Now I written If a value is less than 20 guys you need to give condition inside brackets.
If a value is less than 20 open bracket printf value is less than 20. Here I given one statement that is value is less than 20. If a value is less than 20 then I need to get this out. Here I give a value of a as 10. 10 is less than 20. This condition is true. So whatever the statement that is present inside if will be executed.
So I will get output as value is less than 20. For example here if I give value of a as 100. 100 is not less than 20. 100 is greater than 20. So whatever the statement that is present inside if will not be executed because condition is false. 100 is not less than 20. So I will not get any output. output if I give value of here as 100 guys you need to remember one important thing that is here you need to use int main not void main because based on the conditions we may skip some statements. so you need to use here int min whenever you use here int min definitely you need to write here return zero for example if you want to execute each and every line without skipping any statements then you can use here void min but here we are skipping some statements based on the condition so here you need to use int min same program i will explain by using scanf here instead of initializing value 100 i'm just declaring value that is int a I want to give value of a after executing a program so for that purpose I need to use here scanf but before that I will write one statement that is printf enter number so whatever the statement that is present inside this printf will be seen on my output screen so here I can see enter number now I can enter number by using scanf so I am writing a scanf this a is integer so I need to use here percentage d in double quotations comma and a you should not write a you should write and a where and represent address whenever I write this line of code I can enter any number after executing a program. So whenever I execute program I can see here enter number and here I can enter any number by using scanf.
Now I am giving condition that is if value of a is less than 50 then I should get output as printf. I need to get output as value is less than 50. Value is less than 50. Close double quotation semicolon close bracket return 0 because I am using here int main. So you need to write here return 0. So close main function.
Cc program. It was written int a and I did not initialize any value I will give value after executing a program by using scanf. So I just written here printf enter number and by using scanf I can enter any number and this number will be stored in address a that is this number will be stored in variable a and if a value is less than 50 then I should get output as value is less than 50. So after executing program I can see here enter number so I will enter number that is 40. 40 is less than 50 this condition is true so I will get output as value is less than 50. This is use of scanf.
I can enter value after executing a program by using scanf. For example, if I give here 400, then 400 is not less than 50, 400 is greater than 50. So I will not get any output. This is C program for if statement.
Next I will explain flowchart for this. Guys this is flowchart for if statement. If condition is true, then statements will be executed. Else if condition is false, then directly it will end if. This is flowchart for if statement.
Guys you need to give condition in rhombus. Next I will explain if else statement. If condition is true, then whatever the code that is present inside if will be exuded.
If condition is false then whatever the code that is present inside else will be exuded. This is syntax. Here you need to write if and you need to give condition. If this condition is true then whatever the code that is present inside if will be exuded or if condition is false whatever the code that is present inside else will be exuded. This is program.
Here I written int a equal to 10. I given value of a as 10 and I am giving condition that is if a value is less than 20. Guys you need to write this a less than 20 in brackets and you should never use semicolon here open bracket here I'm giving statement that is printf value is less than 20. If this condition is satisfied then the statement will be executed or if condition is false so I'm writing here else printf value is greater than 20. If condition is true then if statement will be executed or if condition is false then whatever the statement that is present inside else will be executed. So I'm using here intermin So, at last you need to write here return 0 and close main function. Here I give a value of here as 10. 10 is less than 20. This condition is true.
So, I will get output as value is less than 20. For example, in place of 10, if I give here 100, 100 is not less than 20, 100 is greater than 20. So, this condition is false. So, whatever the statement that is present inside else will be executed. So, I will get output as value is greater than 20. If condition is true, whatever the statement that is present inside if will be executed.
If condition is false then whatever the statement that is present inside else will be exuded. This is if-else statement. I will explain flowchart for if-else statement.
Guys this is flowchart for if-else statement. Here you need to give condition. If this condition is true then if statements will be exuded. If condition is false then else statements will be exuded.
And at last you need to give stop. This is flowchart for if-else statement. Next I will explain else if statement.
By using else if statement you can give multiple conditions. If any particular condition is satisfied then whatever the statements that are present inside that block will be executed. I will give one program so that you can clearly understand what is else if statement.
This is syntax of else if statement. At first you need to write if and you need to give condition. If this condition is satisfied then whatever the statements that are present inside if will be executed.
Next you need to write else if and you need to give else if condition. If this condition is satisfied. then whatever the code that is present inside this else if will be executed.
Again you need to write else if and you can give another condition and if this condition is satisfied then this code will be executed at last. If all these conditions are false then whatever the code that is present inside else will be executed. Guys you can take multiple else if conditions.
This is program. At first I written int a equal to 10. I given value of a as 10. At first I am taking if condition. Here I written if a equal to 10. guys definitely you need to use here double is equal to if a double equal to 10 printf value is equal to 10 else if a double equal to 20 printf value is equal to 20 again i written else if a double equal to 30 printf value is equal to 30 at last if all these conditions are false then take else printf number not found here i given value of a as 10 10 is equal to 10 this condition is true so i will get output as value is equal to 10 here in place of 10 if i give a 20 20 is equal to 20 so i will get output as value is equal to 20 for example here if i give 30 then 30 is equal to 30 so i will get output as value is equal to 30 for example here if i give 100 100 is not equal to 10 100 is not equal to 20 and 100 is not equal to 30 so i will get output as number not found so here i return intimate so at last you need to write return 0 and close main function.
This is C program for else if statement. Guys you can use multiple else if statements. You should never use semicolon here for if for else if and for else.
You should never use semicolon and here for else you should never give any condition. Else statement does not contain any condition. So don't give any condition for else.
This is flowchart for else if statement. By using else if statement you can give multiple conditions. So at first I written here start.
I given three conditions. Condition 1, condition 2 and condition 3. As you need to give conditions in rhombus. So I took here rhombus. If this condition is true then the statement will be executed. If this condition is false then it will go to condition 2. If this condition 2 is true then this statement will be executed if condition is false then it will go to condition 3 if this condition 3 is true then it will print statement 3 if this condition is false then it will exit this is flowchart for else if statement next i will explain switch statement this switch statement is same as else if statement it is an alternative to else if statement this is syntax of switch statement here at first you need to write switch and inside brackets you need to write expression expression is nothing but variable name for example here i took int a equal to 0. So here you need to give variable name a.
After that you need to give case and give value and here you need to use colon not semicolon you need to use here colon. This case contains some code. If this condition is satisfied then this code will be executed.
We need to break this case and we need to start new case. So you can take case value to colon. This case contains some code and give break. Guys you can take multiple number of cases and at last you need to give default.
If all these conditions are false then default condition will be executed. So default condition also contains some code. Guys I will give one program so that you can clearly understand what is switch statement.
Here I took int a equal to 0. I given value of a as 0 and after that I took switch inside bracket I given variable name. Here I took variable name as a. So I given here a open bracket.
Here I took case 1. This is nothing but value. I took here value as 1. This is case 1 colon printf number is equal to 1. Here inside this case 1 I am writing statement that is number is equal to 1. Now you need to break this case 1. Again I took case 2 after the time writing statement that is number is equal to 2 and I am breaking this case 2. So I am using here break. Next I took case 3 colon printf number is equal to 3. At last I return default colon number not found. Here I give an value of a as 0. So it will compare this with this case value. Here I give an value of a as 0. Now we need to compare this value with case value that is 1, 2 and 3. 0 is not equal to 1, so this will not be executed.
Similarly, 0 is not equal to 2, this will not be executed. 0 is not equal to 3, it will not be executed. So, I will get output as number not found. So, if all these conditions are false, then default statement will be executed. So, I will get output as number not found.
Here I return int main. So, you need to write return 0 semicolon close main function. this is program here i will get output as number not for example here in place of 0 if i give value of a as 1 here case 1 this 1 is equal to 1 so i will get output as number is equal to 1 if i give value of a as 2 then case 2 this 2 is equal to 2 so i will get output as number is equal to 2. this is c program for switch statement next i will explain flow chart this is flow chart for switch statement this flow chart is same as else if statement at first you need to write start or begin case 1 contains statement 1 case 2 contains statement 2 so on at last you need to use default statement if this case one is true then whatever the statement that is present inside this case one will be exuded similarly if this case one is false then it will go to case two if this case two is true then whatever the statement that is present inside this case two will be exuded so on so if all these cases are not satisfied then at last it will print default statement at last you need to end this this is flowchart for switch statement next i will explain next adf statement If we place one if statement inside another if statement then we call it as nested if statement.
This is an example here I took int a equal to 5 I given value of a as 5. Here I am using two if statements at first I written if a value is less than 10 inside this I am giving another condition that is if a value is equal to 5. So at first a value is placed here 5, 5 is less than 10 this condition is satisfied. So again it will compare another if condition that is a is equal to 5. value of a is 5. 5 is equal to 5. This condition is true. So, I will get output as number is equal to 5. This is flowchart for necessary statement.
At first, you need to give if condition. If this condition is true, then again it will go to necessary condition and if this necessary condition is true, then it will print statement which is present in necessary. If these conditions are false, then it will exit.
This is flowchart for necessary statement. Next, I will explain loops in C. What is loop? Anything that is repeating multiple number of times is known as loop.
For example, I want to print one statement that is my name is Nagendra. So, I return here printf double quotations I written my name is Nagendra close double quotations close bracket and semicolon. Whenever I execute this program then I will get output as my name is Nagendra. For example, I want to get output as Nagendra three times.
So, I need to write printf three times. So, I am writing here printf by writing this program I will get output my name is Nagendra three times but I want to write my name is Nagendra 100 times. So, 100 times I need to write printf and inside the printf I need to write my name is Nagendra but it is impossible to write 100 times it is very complicated. So in order to overcome this problem we use loops by using loops we can write code once and we can repeat this code multiple number of times. So this is main use of loops instead of writing my name is Nagendra 100 times I can simply write my name is Nagendra once and I can repeat this multiple number of times.
So loops are used to repeat block of code until specific condition is met. For example, if I give condition like 10, then I will get my name is Nagendra 10 times. So, loop is used to repeat block of code until specific condition is met. This is definition of loop.
See programming has three types of loops. They are for loop, while loop and do while loop. First, I will explain what is for loop.
This is definition of for loop. For loop exude statements of a program several number of times repeatedly until given condition is met. For loop keep on exuding the statements until given condition is satisfied. This is syntax of for loop.
First you need to write for open bracket and here you need to write initialization. Initialization is nothing but here you need to initialize value to a variable like int a equal to 10 semicolon and here you need to give condition semicolon. At last you need to give increment or decrement operator close bracket. Inside this for loop you can give multiple number of statements. So until this condition is satisfied the statements will be printed.
I will give one program so that you can clearly understand what is this for loop. Here at first you need to write for open bracket and you need to initialize value to a variable. So I'm giving here int a equal to 0 semicolon.
After that you need to give condition. Here I'm giving condition that is a less than 10. This is condition semicolon and I'm using increment operator i++. I will explain this. Here inside this for loop I'm writing statement that is how are you. So I'm writing here printf open bracket open double quotations how are you.
This is statement which I written use here slash n. because whenever you use here slash n how are you will be printed on next line. So use here slash n inside double quotations close these double quotations close bracket semicolon close this for loop and at last close main function you need to close for loop and at last you need to close main function.
I given value of a as 0. So 0 is less than 10 condition is satisfied. So if condition is satisfied whatever the statement that is present inside for loop will be executed. So I will get output as how are you.
After that here I am using increment operator. So it will increment value of 0. i plus plus is nothing but i plus 1 0 plus 1 that is 1 so it will increment value to 1 1 is less than 10 condition is satisfied so again i will get output as how are you again it will increment value of 1 after incrementing value 1 i will get 2 2 is less than 10 condition is satisfied so again i will get output how are you after that 3 3 is less than 10 condition is satisfied 4 is less than 10 condition is satisfied i will get how are you 5 6 7 8 9 from 0 to 9 9 is less than 10 so again i will get output how are you After incrementing value 9, I will get 10. 10 is not less than 10. 10 is equal to 10. This condition is not satisfied. So it will stop this loop. So, starting from 0 to 9, total 10 times I will get output how are you.
This is C program for for loop. For example, if you want to print multiple statements like how are you, I am Nagendra. So, right here printf my name is Nagendra slash n double quotations close bracket semicolon.
Whenever you execute this program, then how are you and Nagendra both will be printed 10 times. This is C program for for loop. Instead of writing how are you 10 times, you can simply write how are you once. and you can repeat this until particular condition is satisfied.
For example, if I give condition here a less than 100, then I will get output how are you 100 times. For example, I want to print numbers from 0 to 9 by using for loop. So at first I'm taking here int a equal to 0 because I'm starting number from 0. So I return here int a equal to 0. I'm starting from 0. So I given value of here 0 semicolon and I'm giving condition I want to I want to print numbers from 0 to 9. So at last I need to get 9. So I'm giving here condition that is a less than 10 semicolon. I keep on incrementing values like 0, 1, 2, 3, 4 like that.
So here you need to use a plus plus close bracket inside this you need to write printf percentage d. Definitely you need to use here slash n because whenever you use here slash n next statement will be printed on next line. For example, if you don't use here slash n, then you will get output 0, 1, 2, 3 like that. So use here slash n, double quotations close, comma a. Value is present in variable a.
So I'm giving here a semicolon. Whenever you execute this program, then at first it will take value 0. 0 is less than 10. So it will print value 0 and it will increment value. After incrementing 0, I will get 1. 1 is less than 10. Condition is satisfied.
So it will print 1 in next line. And again, it will increment value 2. 2 is less than 10. Condition is satisfied. it will print 2 and again it will increment value so now i'll get 3 3 is less than 10 so it will print 3 and again it will print 4 5 6 7 8 8 is less than 10 so it will print 8 and again it will increment value that is 9 9 is less than 10 so it will print 9 and at last it will increment value to 10 10 is not less than 10 10 is equal to 10 So, this condition is not satisfied.
So, it will break loop. This is C program in order to print numbers from 0 to 99. For example, if you want to print numbers from 0 to 99, then you need to use here a less than 100. So, it will place 0, 1, 2, 3, so on until 99. For example, if you want to print numbers from 0 to 100, then just you need to write here a less than or equal to 100. So at last it will take 100, 100 is less than or equal to 100. So, I will get output from number 0 to 100. This is C program for for loop. At first you need to write start. After that you need to initialize.
value to a variable. So you need to write initialization in rectangle. After that you need to give condition.
I already said before you need to give condition in rhombus. So give condition in rhombus. Until given condition is satisfied statements will be printed.
Whenever it prints statements it will increment value. So write here increment or decrement operator in rectangle. Until this condition is true statements inside this furlough will be printed and whenever it prints statement it will increment value and after incrementing value again it will check condition. In it loss if condition is false then we can stop for loop. So it loss right here stop.
This is flow chart for for loop. Next I will explain while loop. Guys this definition is same for all these three loops.
So you can write this definition for while loop. This is syntax for while loop. At first you need to write while and inside brackets you need to give condition. Until this condition is satisfied then whatever the statements that are present inside this while loop will be executed. Guys definitely you need to give here increment and decrement operator guys i will give one example so that you can clearly understand what is this while loop same program which i have explained before for for loop i will explain the same program by using while loop here i want to print how are you 10 times so at first i am writing here int a equal to 1 starting from number 1 so i return here int a equal to 1 after that inside while i am giving condition that is a less than or equal to 10 open curly bracket inside this you can give your statement that is how are you slash in double quotations close close bracket semicolon here you need to write increment operator that is a plus plus guys definitely you need to give your increment operator because we are incrementing each and every value so it will take value 1 1 is less than 10 condition is satisfied so it will print how are you again it will increment value to 2 2 is less than 10 condition is satisfied so again it will print how are you it will increment value to 3 3 is less than 10 it will print how are you again it will increment value to 4 5, 6, 7, 8, 9, 10. At last it will take value 10. 10 is equal to 10. So this condition is satisfied.
So I will get output how are you from 1 to 10. So total 10 times it will print how are you. For example if you want to print how are you 100 times just in place of 10 you can give here 100. So whenever you give like this you will get output how are you 100 times. For example I want to print numbers from 1 to 5. So at first I return int a equal to 1 because I am starting from 1 and I am giving condition that is while.
a less than or equal to 5. Here I am giving a less than or equal to 5 because I want to print numbers from 1 to 5. So, shorting from 1. to 5. In order to print this value you need to write printf %d,a because value is present in variable a. So I written here %d,a and here you need to write a++. Whenever you execute this program at first it will take value 1 because I have given here a equal to 1. So at first it will take 1, 1 is less than 5. So it will print value 1 printf %d,a whatever the value that is present inside this variable a will be printed as %d,a.
output so I will get output 1 so by using increment operator a++ it will increment value 1 so after incrementing value 1 I will get value 2 2 is less than 5 condition is satisfied so it will print 2 and again it will increment value to 3 3 is less than 5 so it will print 3 again it will increment value to 4 4 is less than 5. So it will print 4 and again it will increment value to 5. 5 is equal to 5. Condition is satisfied. So I will get output 5. So again it will increment value that is 6. 6 is not less than or equal to 5. 6 is greater than 5. So it will break while loop. We call this for loop and while loop as entry controlled loops because at first it will check condition.
Only if this condition is true then whatever the statements that are present inside this loop will be printed. If this condition is false. then whatever the statements that are present inside this loop will not be printed.
So we call this for loop and while loop as entry controlled loops and we call this do while loop as exit control loop because at first it will print statements after printing statements it will check condition for entry controlled loops at first it will check condition only if condition is true then whatever the statements that are present inside this loop will be printed. But whereas for exit control loop at first it will print statements after printing statements it will check condition whether condition is true or not. I will explain this do while loop. This is syntax for do while loop.
At first you need to write do. Inside this do you need to give some statements and at last you need to give here increment or decrement operator. Here write while and inside bracket you need to give condition and you need to remember one important thing that is here definitely you need to use semicolon. For do while loop for while condition at last you need to give semicolon.
I will give one program so that you can clearly understand what is this do while loop. Here I want to print numbers from 1 to 10 by using do while loop. So at first I am writing here int a equal to 1 because i am starting from 1 and here you need to write do in order to print this value you need to write printf %d slash n comma a guys for all these three loops definitely you need to use increment operator or decrement operator here i want to get output from 1 to 9 i keep on incrementing value so here i need to use increment operator that is a plus plus close bracket and inside while you need to give condition so you need to write here while here i want to print output from 1 to 10. So here inside this while loop I am giving condition that is a less than or equal to 10 and definitely you need to give here semicolon for do while loop and close this main function.
Whenever you execute this program at first it will print value 1 after that it will check condition. So condition is true. So again it will print 2 3 4 5 6 7 8 9 10. So by writing this program I will get output 1 to 10. For example if I want to print numbers from 1 to 1000 then just in place of 10 you need to give here 1000. Whenever you give here 1000 then you will get output from 1 to 1000 numbers. Guys this is flowchart for while loop and do while loop.
This is flowchart for while loop. At first you need to start here for while loop you need to give while condition. Until this condition is satisfied whatever the statements that are present inside this while loop will be exuded.
Whenever condition fails then it will stop this loop. This is meaning of this while loop flowchart. Next I will explain flowchart for do while loop.
At first you need to write do. Inside this do you need to give some statements and these statements will be printed until this while condition is satisfied. Here you can give while condition. Until this while condition is satisfied then whatever the statements that are present inside this do will be printed and whenever condition reaches to false then it will stop this loop. In exam they may ask difference between while loop and do while loop.
Here I given value of a as 100 but here I given condition that is a less than 10. 100 is not less than 10. 100 is greater than 10. So whatever the statements that are present inside this while loop will not be executed. So here I will not get any output because in while loop at first it will check condition only if that condition is true then whatever the statements that are present inside while loop will be executed. But whereas in do while loop here I give an value of here as 100. 100 is not less than 10, 100 is greater than 10. So here I will get output 100 because in do while loop at first it will print statement After printing that statement, it will check condition. So here at first it will print 100. After that, it will check condition.
100 is not less than 10. 100 is greater than 10. So it will stop this loop. So whereas in while loop, it will not print any output. But whereas in do while loop, it will print first value.
Guys, in exam, they may ask explain control structures. Control structures are classified into three types. They are conditional statements, loops, and conditional operator. A conditional statements contains if, if else, else if, switch and necessary if statements.
Whereas loops contains while loop, do while loop and for loop. Conditional operator is nothing but ternary operator. So whenever control structures question comes in exam then you need to explain all this in detail.
Guys just remember these basics int will occupy two bytes of memory and for some systems it will occupy four bytes of memory. Whereas character will occupy one byte of memory. and float will occupy 4 bytes of memory. Next topic is break continue and go to statements in C.
At first I will explain what is a break statement. This break statement is loop control statement that mean if you want to break any loop then you need to use this break statement. I will give an example so that you can clearly understand what is this break statement. Now I am using break statement inside for loop. I want to print numbers from 0 to 9. So here I took for loop inside for loop I written int i equal to 0 i less than 10 i++ and in order to print these numbers from 0 to 9 i need to write here printf 0 1 2 3 all these are integers so i written here printf percentage d comma i because all these values are present in variable i so i written here printf %d comma i by writing this program i will get output as at first it will take value 0 0 is less than 10 condition is satisfied so it will print 0 here i written i plus plus so again it will increment value that is 1 1 is less than 10 condition is satisfied so it will print 1 again it will increment value now it will take 2 2 is less than 10 condition is satisfied so again it will take 3 3 is less than 10 condition is satisfied so it will print 3 like that it will print up to nine numbers five six seven eight nine nine is less than ten so it will print nine and again it will increment value that is ten ten is not less than ten ten is equal to ten so it will break this condition up to nine so it will stop this loop now here i am using break statement if i equal to four break and you need to give semicolon for break that mean if i get i value as four then i want to break this loop this is meaning of this if If I equal to 4 break whenever I write this at first it will print value 0 again it will print 1 2 3 and 4 whenever it reaches to 4 then it will break this loop.
So by writing this program that is if I equal to 4 break then I will get output as 0 1 2 3 4. This is my output. This is program for break statement. I'm starting loop and inside this loop I am writing condition in order to break the loop like if I equal to 4 break.
So inside for loop. I am writing condition to break the loop. If this condition is true, then it will break the loop.
Else if condition is false, then it will continue this loop. This is flowchart for break statement. Next I will explain continue statement. This continue statement is same as break statement. Only difference is that break statement is used to terminate the loop, whereas continue statement is used to continue the loop.
I will give an example so that you can clearly understand what is continue statement. In this program, I given condition that is if i is equal to 4, then I given condition as break. So by writing this program I will get output as 0 1 2 3 4 but here in place of break if I write here continue by writing this program I will get output as 0 1 2 3 4 5 6 7 8 9 in continue if I reach value to 4 it will continue the loop.
So by writing this program I will get output as 0 1 2 3 4 5 6 7 8 9 this is my output whereas in break if condition is false then it will continue loop and if condition is true then it will break the loop but whereas in continue if condition is false then it will continue the loop and whereas if condition is true even though it will continue this loop same example if i reach value to 4 it will continue the loop so if condition is false then it will continue the loop and if condition is true even then it will continue this loop so this is program and flow chart for continue statement guys whenever break statement question comes in exam you can also write switch statement example because in switch statement also we use break condition so you can also write switch statement as example Next I will explain goto statement. If I write any program by using goto statement then that program is very hard to understand and modification of that program is very hard. So any programming language do not recommend goto statement. This is syntax of goto statement. At first you need to write goto and you need to write label.
Label is nothing but any text any name is known as label. It should not contain any keywords. So at first you need to write goto label and label contains some statement.
I will give one program so that you can clearly understand what is goto statement. This is program for goto statement. At first you need to write goto. Label is nothing but any plain text. Here I'm giving any text like college.
I give a label as college and definitely you need to give a semicolon. Now you need to write label and label contains statement. Here I give a label as college. So you need to write here college colon statement is nothing but I'm writing statement as printf my college.
By writing this program I will get output as my college here at first i didn't go to i given label as college so this college contains statement that is my college so by writing this program i will get output as my college this is flowchart for go to statement here at first i written label one this label one contains statement one and similarly label two contains statement two and label three contains statement three after that i return go to label three that mean it will go to label three label three contains statement three so whatever the statement three that this label three contains i'll get this statement three as output For example, if I write here goto label to then whatever the statement that this label to contains, I will get this statement to as my output. This is flowchart for goto statement guys now I will explain C program in order to print this full table by using goto statement. Here total I need to take two variables one is for this number four and another one is for number one, two, three, four up to 10. For example, I will take variable name as number NUM for this number four and I will take another variable.
that is for number 1 2 3 4 up to 10 for example let variable name be i so here i am taking two variables one is for number 4 and another one is for number 1 to 10. so here you need to write int these both are integers so here i need to write int number equal to 4 comma here i value starts from 1 so here i need to take i equal to 1 now we will write goto statement at first i am taking label let label name be table you can also take any label name here i am taking label name as table, give colon, now write printf %d x %d is equal to %d, this %d is for number that is number four and this %g is for variable i and this %g contain result. result is nothing but number into i semicolon. at first you need to write 4 into 1 equal to 4 after 4 into 1 you need to take 4 into 2 after 2 3 after 3 4 like that you need to write up to 4 into 10 equal to 40. so here we keep on incrementing i value like 1 1, 2, 3, 4 up to 10. So here you need to write I++. Now give condition here you want to print for table up to 4 into 10 equal to 40. So here you need to give condition that is if I value is less than or equal to 10 that is from 4 into 10. If I value is less than or equal to 10 go to table here I given label name as table.
So here you need to write go to table. semicolon by writing this program you will get output as 4 into 1 equal to 4 4 into 2 equal to 8 4 into 3 equal to 12 like that you will get up to i less than or equal to 10 that is 4 into 10 equal to 40 up to 4 into 10 equal to 40 i will get my output this is how we print tables by using go to statement for example if you want to print 10 table then here in place of 4 you need to write 10 that's it this is how we print tables by using go to statement this is important question like in exam they may ask like write phi table by using go to statement so whenever that question comes in exam you need to write this program next topic is story classes in c and also i will explain scope and lifetime of a variable in c at first i will explain scope of variable where a defined variable can have its existence and beyond that we cannot access that variable that mean for example if you define any variable like i am defining variable as int a equal to 10 this a is my variable and i declared this variable inside main function Inside main function, I declared variable name as a. Scope is nothing but existence of a variable.
For example, here I written int a and I written this inside main function. So, this variable a existence is only inside main function and I cannot access this variable a outside the main function. So, where a defined variable, this defined variable is a. Where a defined variable can have its existency and. Beyond that we cannot access that variable.
So I cannot access this variable a outside the main function because this existence is present only inside main function. This is meaning of scope of variable. In C programming we can declare variables in two places. One is inside the function and another one is outside the function. For example variables which are declared inside the function is known as local variable and variables which are declared outside the function is known as global variable.
I will give example of local variable. At first you need to write hash include htd.h after that void main. This is main function which I am taking. Inside main function I am declaring variable that is int a equal to 10. I given variable name as a and value as 10 data type as int. Now I want to print value 10. So for that purpose we need to use printf.
This a is integer so you need to take here percentage d comma a. So by writing this code I will get output as 10. So this a is local variable because we declared this a inside main function. So we call it as local variable. Now I will explain program for global variable. Same program which I written before.
At first I written hash include stdo.h after that I written int a equal to 10. Here I am declaring variable outside the function. So we call this a as global variable. After that you need to write void main. Inside void main you need to write printf percentage d comma a. By writing this program you will get output as 10. Here we declared variable inside main function.
So we call this variable a as local variable. And whereas here we declared variable a outside the main function. So we call this a as global variable.
Here variable existence is only inside the function. that is only inside this block and whereas here variable existence is present until entire program. Lifetime of a variable is a time for which particular variable is present in our memory.
How much time particular variable is present in our memory? This is known as lifetime of a variable. We can store variable either in main memory or in CPU register.
These are two storage locations in order to store particular variable. Scope and lifetime of a variable is specified by storage classes. Storage classes are used to specify way to store the variable. That is either we need to store variable in main memory or in CPU register.
And storage classes are used to specify scope and lifetime of a variable. Storage classes are classified into four types. One is auto and next one is static and next one is external and last one is register. These are four sore classes that we need to use. Guys, you need to remember this table.
First one is auto. Here I written auto int a equal to 10. Whenever you declare like this, then this variable a is stored in main memory and this scope is within the block. That mean I can access this variable only within this block. I cannot access this variable outside the block and lifetime of a variable is until end.
of block that mean this variable will expire whenever I close this block in place of auto if you use static then this variable a is stored in main memory and scope is within this block that mean we cannot access this variable outside the block and lifetime is till end of the program that mean variable is present whenever we declare this variable and until end of the program end of the program this variable will be present. So this lifetime is until end of the program and next one is register. In place of static if you declare register then this variable a is stored in cpu register and scope is within this block that mean I can access this variable a only within this block and lifetime is until end of the block that mean from starting variable declaration to until end of this block this variable will be present.
Next one is extend. If you use extend then variable is stored in main memory and scope of variable is global multiple files whereas in auto static and register scope is only within the block that mean we can access this variable only inside this block and we cannot access this variable outside the block but whereas in extern scope is global multiple files that mean we can access this variable even outside the block and lifetime is till the end of the program. Now I will explain program guys this is program for auto here I written hash include htdvo.h after that I written void min. and here I declared auto into a equal to 10. Whenever you declare like this, this variable a is stored in main memory and here I written printf percentage d comma a.
Whenever you write like this, you will get output as 3 because value of a is 3. So, I will get output as 3. For example, if you want to use static, then just in place of auto, you need to declare static and if you want to use register, then just you need to write here. register in place of auto so whenever you write register into a equal to 3 then this variable a is stored in cpu register next this is program for extend if you want to use extend storage class the name itself says extend mean we need to declare variable outside the main function so if you want to use extend storage class then you need to declare variable outside the main functions so here i written hash include htd over dot h after that i written extend int a equal to 1 after that I return void main and inside void main I return printf percentage d comma a where auto static and register are declared inside main function but if you want to use extend story class then you need to declare this extend story class outside the main function so I return here extend int a equal to 10 and inside main function I return printf percentage d comma a whenever I write like this I will get output as 1 because value of a is 1 next topic is what is type conversion Converting one data type value into another data type is known as type conversion. We also call this type conversion as type casting. There are two types of type conversion. One is implicit type conversion and next one is explicit type conversion.
Now I will explain what is implicit type conversion. Implicit type conversion converts smaller data type value to larger data type. For example, if you consider integer, this integer is smaller data type. So if we convert this integer to any larger data type like float, then we call it as implicit type conversion.
In implicit type conversion converting one data type to another data type is done by system itself automatically. So definition of implicit type conversion is the type conversion which is done by system itself automatically is known as implicit type conversion. I will give one example so that you can clearly understand what is implicit type conversion.
In this program I written int a equal to 10 by 3. after that i written printf %d,a for example if you calculate this 10 by 3 in your calculator actually you should get value as 3.333 so on but here i will get output as 3 because here i took integer so it will print only integer value so computer automatically converted one data type into another data type this is known as implicit type conversion in implicit type conversion conversion which is done by system itself automatically is known as implicit type conversion So it automatically converted this 3.333 value into 3. Next I will explain explicit type conversion. Implicit type conversion converts smaller data type to larger data type. Whereas explicit type conversion will convert larger data type to smaller data type. And definition of explicit type conversion is type conversion which is done by user manually is called explicit type conversion.
In implicit type conversion converting one data type to another data type is done by system itself automatically. But whereas in explicit type conversion. converting one data type to another data type is not done by system automatically.
So, user should manually convert one data type to another data type. I will give an example so that you can clearly understand what is explicit type conversion. This is program here I written float a equal to 10 by 3 value of this variable a is 10 by 3. After that I written printf for float we need to use percentage f comma a. By writing this program I will get output as 3.000.
Actually value of 10 by 3 is 3.333 but here I got output as 3.000 which is wrong value why I got wrong output because though I given here data type as float here I took value as integer this 10 is integer and this 3 is integer value so I got output as 3.000 in explicit type conversion converting one data type to another data type is not done by system automatically so here system unable to convert this integer value to float value so I got here wrong output for example here in place of 10 if you give here 10.0 and in place of 3 if you give here 3.0 then you will get output as 3.333 so here system unable to convert this integer values to float value so here i got output as 3.000 which so user should manually correct it so here i manually changed this value of 10 to 10.0 and 3 to 3.0. This is known as explicit type conversion. Next, I will explain C program to check whether number is even or odd. Before that, you need to know what is even number and what is odd number. For example, if we divide any number by 2 and if we get remainder as 0, then we call it as even number.
Else, we call it as odd number. I will give an example. For example, if you consider 4, if we divide this 4 by 2, 2 2's are 4. So, we got remainder as 0. So, 4 is even number.
For example, if you consider phi, two twos of four, I got remainder as one. So this phi is not even number. This phi is odd number.
I will write C program to check whether number is even number or odd number. I took here int. I given variable name as number in um. I want to check whether phi is even number or odd number. So I given here value of number as phi.
Now I want to check whether this phi is even number or odd number. If number is divided by two and if you get remainder as zero, then it is known as even number. So right here printf.
even number semicolon close bracket else printf odd number close bracket for else and next close bracket for this mean this is programmed to check whether number is even or odd here if we divide 5 by 2 we will get remainder as 1 not 0 so this 5 is odd number so output is odd number next I will explain what is an expression here I written b equal to c plus d we call this c plus d as expression where c and d are operands and place is operator and this b is variable not only c plus d for example if you consider a into b plus c we call this a b c as operands and this into and place as operators we call this as expression a into b plus c is an expression a plus b plus c by 3 this is also an expression expression is combination of operands and operators there are various types of expressions these are the examples of arithmetic expressions like 10 into 20 10 plus 20, a plus b into c. All these are examples of arithmetic expression. Next examples of logical expressions. They are a or b, a and b. These both are examples of logical expression.
And next a not equal to b, a less than or equal to b. These are the examples of relational expression. Next I will explain what is precedence and associativity. Precedence means priority. Which operator has high priority and which operator has low priority.
Here first priority is for brackets. and next second priority is for multiplication and division and third priority is for plus and minus this is an example here we need to give first priority for multiplication so at first we need to calculate 1 into 2 that is 2 after that we need to give priority for addition so after that 2 plus 3 is 5 this is another example here we need to give first priority for brackets so at first we need to calculate 1 plus 2 because they are present in brackets so 3 into 3 plus 1 after that next priority is for multiplications after that we need to multiply 3 into 3 that is 9 plus 1 last priority is for addition so 9 plus 1 is 10 this is my answer precedence is nothing but priority which operator has high priority and which operator has low priority based on that we need to perform calculations next I will explain what is associativity here this plus and minus both operators has same priority precedence of this plus and minus is same if two or more operators of same precedence appear in expression Then at that time, we need to use associativity. That is from where we need to start calculation. We can start calculation either from right to left or left to right. This plus and minus both are arithmetic operators.
For arithmetic operators, associativity is from left to right. So, we should start from left to right. So, at first we need to perform 1 plus 2 that is 3. After that 3 minus 3 that is 0. This is my result. This is precedence and associativity table.
Definitely you need to write this table in exam. Whatever the examples that I explained you need to write these examples and as well as this table in exam. Next topic is command line arguments in C. Why we call it as command line arguments because whenever you write command line argument program and then you execute it then it will open command prompt whenever you execute command line argument program then it will open command prompt and inside command prompt you need to pass arguments for example testing testing is argument so arguments which are passed from command line is known as command line arguments arguments passed from command line are called command line arguments these arguments are handled by main function normally we write main function like this and we do not pass any arguments inside this main function but whereas in command line arguments you need to write syntax like this void main and inside main function you need to pass two arguments one is argc that mean argument count and next one is argv that mean argument vector. So, in order to support command line arguments you need to change structure of main function like this.
This is syntax you need to remember. In above syntax the command line arguments their argument count and argument vector have been handled via main function. In above statement this command line arguments are handled by main function where argc mean.
argument count that denotes number of arguments to be passed how many arguments we are passing it will count that arguments and next one is argv that mean argument vector that denotes a pointer array this is pointer array that is pointing to every argument that has been passed to your program that mean by using this argument vector we can pass arguments. These arguments are string type. So character along with array represents string and whereas argument count is integer because how many arguments that we are passing it will count those arguments.
For example, in command prompt I am passing two arguments like testing and testing. I can pass these arguments that is testing and testing by using argument vector because character along with array represents string. So, this testing is string character. So, I can pass this arguments by using argument vector and whereas argument count name itself says it will count how many arguments that we are passing.
So, we are passing two arguments. So, count will be two. This two is integer.
So, here I written int argc that is to count arguments and next one is argument v. By using argument v, we can pass arguments. You must make sure that in your command line arguments argument vector 0. Stores the name of your program and similarly argument vector 1 gets a pointer to the first command line argument that has been supplied by the user and argument vector n denotes the last argument. Meaning of this is for example this a.out is my program name. This program name is stored in argument vector 0 and I am passing argument that argument name is testing so this testing is stored in argument vector 1 for example if I write testing again then this is stored in argument vector 2 I will give one program so that you can clearly understand this is program for command line arguments at first you need to write hash include htdio.h after that you need to write int main and inside main you need to write int argument count that is argc comma character pointer argument vector now open bracket inside this you need to write printf program name inside this you need to write program name program name is string type so you need to write here percentages slash n comma this program name is stored in index number 0 so here you need to write argument vector 0 meaning of this is this program is string type that is stored in argument vector 0 next write if argument count is equal to 2 if argument count is 2 for program name count is 1 and if you pass any argument then count will be 2 So, if argument count is equal to 2, then printf the argument supplied is percentage s slash n comma argument vector 1. Whenever you write this, for example, my program name is a dot out. This a dot out is stored in argument vector 0 and for example, I want to pass argument that is testing.
Whenever you pass this argument, then you will get output as the argument supplied is testing and this testing is stored in argument vector 1. This testing is string character so I written here percentages. Next else if argument count is greater than 2 that mean if I pass multiple arguments then I will get output as printf too many arguments. For example if I pass this same argument again that is if I pass this testing again then I will get output as too many arguments because for this program name count will be 1 and for this argument count will be 2 and for this count will be 3. So, condition is if argument count is greater than 2. So, I will get output as too many arguments.
Next else. Else if I do not pass any arguments, then I will get output as printf no arguments. For example, if I do not pass any arguments, then I will get output as no arguments.