Techie Sagar
Data Types in C (part 2)
Data Types In C (part 1)
Rules of Declaring a Variable.....
Some Of The Important Rules To Declare VARIABLES In C.........
Variable (part 1)
variable in c...
In today's lesson,we are going to talk about variables in C programming. Think of a glass of water.If you want to drink some water, then you put water inside glass and drink it. You can think of a variable as a glass of water.As a glass can store water in it similarly variables can store some value in it.After storing the value,you are free to use this value in your program.
In reality, variables are simply names that points to some memory location.Thanks to the inventor of C language who makes it easy for us to store values in memory by simply using the name of our choice.You don't need to worry about at which location of the memory your value is stored. Your task is to just provide the name and internally it will point to some memory location.But there is one thing that we need to be sure about.You must have to declare variables before using it in your program.Declaration simple means,announcing the properties of the variable to the compiler. Here, by saying properties we mean that what will be the size of the variable and what will be the name of the variable Don't worry, it is not a very difficult job to do.You will see in a moment how easy it is to declare a variable.
There is one more term called definition of a variable,which means allocating memory to a variable.Most of the time declaration and definition will be done at the same time.But this is not always the case.It depends on the modifiers you had mentioned with the variables. We will talk about modifiers later and then we will also explain how declaration and definition is different for different modmodifier Let me give you an example of how to declare a variable.Here, the name of the variable is var and it has an integer data type.Data type simply means how much space a variable is going to occupy in the memory.Therefore by writing....... int var you are declaring a variable along with that you are requesting the compiler to allocate memory for this variable. Please note down on one thing here after int varwe have put a semicolon over here.This is very important.Because this is how your compiler separates one statement from the other.So don't forget to add a semicolon at the end of the variable.
Now, the memory location depends upon the type you use Here because in our example,we are using integer data type therefore it may take either two bytes of memory or may be four bytes of memory.It purely depends on the system you are working on. Again you don't have to worry about how much space is allocated to your variable.You only have to concentrate on the declaration and definition of the variable If you assign some value to a variable,at the time of declaration itself Then this thing is called initialization.This is how you will do initialization. Note- initialization of a variable doesn't mean that you cannot change the value of a variable afterwards in your code.If you want the value to be changed somewhere,then you can do that this clearly captures the meaning of variable.Variable in its pronunciation has word vary.Something that can vary over time.On the other hand constant is just the opposite.once defined will never change.
Let's see how we can change the value of the variable after initialization.Let me write down the code here.I am writing .........#include that is our header file because we have to print some output. Then I am declaring main function.Inside this main function,I'm first declaring a variable named var.Suppose I initialize it first to 3,and afterwards I change this value to 4.You can observe that again I have not written int var in this statement when I'm assigning value to it.because the memory is allocated to the variable once and defining it once again means you want to allocate memory again for the same name. And this is illegal.Note- each variable must be defined only once but it can be used multiple times with different assignment in your program.But there is one exception as well.when we study scope rules later you will understand that same variable name can be defined in different blocks of code.You will slowly understand what does it mean.For now it is enough to know that inside this main function you cannot define multiple variables with the same name.Then suppose we write,printf with %d and we print the value of the variable.I will explain you more about what this %d means.For now, I can only tell you that this will print the contents of whatever is there inside this variable var you have to put at the end return 0 Let me save this.And build and run the code.You can see the output here which is 4. Previously I had initialized the Value of 3, and then changed it to 4 and print it.And as expected,my output is equal to 4 without any error.
You can also assign variable to a variable instead of this constant value 3 or 4.int var1 is equal to 3. Suppose my new variable is var1,I declare another variable var2 and I initialized or you can say I assigned value to it with the value of var1.Here you can see that I am assigning the value of 3 actually because writing the name of the variable means that I am assigning its constant value and I'm assigning it to variable 2. Lets print it using printf.Lets debug As expected, the output turns out to be 3.You can also assign same values to different variables in a single line.As you can see I declared and defined variables in the same line using the same data type.All these variables are of integer type.Instead of defining and declaring in different lines it is better to write them down in a single line.Suppose I assign them the value equal to 4 all in the same line and then I print it.
Lets build and run.And as expected we get the value 4 4 4 because we had printed three times.There are three different variables var1 var2 var3. Because all of them has been assigned to the same value 4 That is why we are getting three values of 4 in the output.
Constant In C (part 2)
constants in c
Let us discuss now character constraints these are also two types single character and string string constant what is single character constants if i write like suppose single character is a so you will write like this in single quotation so this is what character constant constant so you can say character constant is what it is having a single character enclosed within single quote marks this is character constant this is also character constant and suppose i write this backslash this one zero this is also character constant these are backs backslash character constraints these are having different meanings there is list of backslash character constants right those are having different meanings fine and you can say like if you write this one comma this is also character constant right and if you write this at the rate this is also character constant so any single character which is enclosed within these single quotation mark within this you can also write down some characters also like a b c d capital a b c d or some numbers and some special characters also those are character constraints and these character constraints are within computer it these are being stored in the form of sky codes right like uh here this a means 97 capital a means what 65 like this small b means 98 and like this capital b means 66 and like this so on right and these are also having uh their different this this value this is also character constant if you write 1 and see 5 is not equal to this 5 this is character constant it is having some different value this is numeric constant this you need to take care right if you are writing anything between these single quotes the number then that is character constant that is not numeric constant this is not integer constant fine so sky value i am writing here you can see so these are sky values capital a to z 65 to 90 small a to z 97 to 122 zero to nine numbers are having a sky value 48 to 57 and some special character like this um coma or at the rate or some special characters are having values from 0 to 47 then 58 to 64 and 91 to 96 right you can also check out like which special character is having between these lie between these values and between these and between these you can google it out right but you have to take care of this thing and you can also perform some arithmetic operations on these character constants right suppose i am printing uh thissee if you are writing like this percentage printf percentage d this is for integer format specifier and a it is what single quote mark so this is what character constant so it will print what integer value of this a because i am writing here format specifier percentage d this is for integer this is to print integer value right here if you compiler will find it is percentage d then it will print what whatever is given here after this coma the first one the first one for that it will print the decimal value means that that integer value the integer value of a is 97 so it will print 97 and if you write percentage c it is what character constant it is used to print characters and if you write here 97 then it will print the equivalent value character value of this 97 fine and see every character is having integer value that is why i am saying that you can also perform arithmetic operations on character constants right next comes to string constant so string constants are you can say sequence of characters enclosed within double
characters and enclosed within double quote mark so this is string constant if you write abc this is what string constant and these characters may be letters number some special characters space everything if i write like uh here a b dollar this is also string constant but here c one thing if i write a in double quote this is not it is single character but enclosed in double quotation mark so it is not character single character constant it is a string constant and if i write a this is what single character constant but these are not equal this is different thing this is different thing this you need to take care this is string constant this is what character single character constant fine and if i write like 1 2 3 4 5 in double quote this is also string constant right but here this like 1 is not equal to this one because this is single character and it is equivalent to its sky value of 1 is 49 but string constant this is not equal to its sky value this is string constant right so you need to take care of this thing also and whenever this string constant is there in a program and when compiler read this string constant then what compiler will do compiler will store the address of the first character reads the address of the first character and it will append a null character constant it will append a null character constant at last why so just to mark this is end of the screw end of this string right so length of the string is what one two three four five six here if you find out the length of this string then it is not five it should be six because a compiler has added null character just to mark that this is end of this string fine so now let us discuss how to declare constants in your program we use what keyword const keyword to declare constant like this right one method is this one so if you write in a program suppose i am writing a function word main i am not writing a complete program you can include those header files and i am writing here const int a value is 10 in this program right means this value of a is constant throughout the program you cannot change this value if suppose you will print this value a then always the output would be 10 and suppose after that i am writing a is equal to 50. you are trying to change the value of a then it this line will give error that this value is you can say its read only value you cannot change this value because you have written conest keyword before this declaration before this initialization of this variable this is variable name that also will discuss what are variables in c this is data type but if you write like this into a is equal to 10 fine when you will print value of a 10 would be printed but after that anywhere in a program you can change this value if you write a is equal to 50 and then if you print value of a then the updated value would be printed 50 now you can change this value this will not give error so you have to declare constant using const keyword right another thing it that i have discussed in starting of this video you can use hash define macro definition symbolic constant so there you can write this would be above this main although you can use anywhere the hash define statement but generally we use where above this main function right so we write like what hash define suppose i am writing a 10 this is also fine right but generally here we write what capital uh letters only like if you're writing pi then pi also if you write max then max also like this right and why i am using these capital letters so that you can distinguish between the normal variables within the programs and the symbolic constraints that is why there are some rules when you use this hash define statement then there are some rules to write this the statements and what are those rules there should not be any space between hash and define there should also be a space between hash define this and then name of that constant and then value of that constant another thing you cannot use here equal to right this would be wrong fine you cannot use semicolon after a statement.
Constant in c (part 1)
constants in c.....
constants so that we use to define some fixed values like suppose um value of pi so you will write hash define pi is 3.14 this is what that definition section we have discussed when we were discussing structure of a c program so the value of pi is fixed 3.14 it is symbolic constant if you write hash define suppose max value is 50. so the value of that max is what is to be 50 throughout the program it is not going to be change you cannot change that value these are symbolic constants right so we are having basically two types of constants in c
1] numeric constants
2] character constants
or somewhere it is also written four types of
1] constant integer
2] floating point constant
3] character constant
4]string constant
let us discuss so these are four types of constant or you can say two types numeric and character constant is numeric is further divided into two types integer constant and real constant of floating constant here single character constant string constant so basically four types so let us discuss first one is integer constants these are having decimal values like if you write this uh 10 it is it is a constant five integer constant one integer constant integer constant right these are valid but if you write 0 5 this is not you can say decimal constant see in integer also we have 3 types decimal constant octal constant and hexadecimal constraint right decimal means we can use uh the the numbers from 0 to 9 base is 10 octal constant means from 0 to 7 base is 8 and hexadecimal means we can use from 0 to 15 and bases base of these constants are 16 so integer also having three categories so if you write 0 5 that comes under ah octal constant because the rule is what octal constants starts with the value 0 always right but decimal constant means yeah you can use 0 but if there are two digit in that constant so 0 can be at this side right side but 0 cannot be at this side left side if you write like this this comes under category octal constant right and constants are also called literals right so here also you can we can express an integer in three forms decimal octal and hexadecimal and by default if we say integer constant generally by default we represent that in decimal constant not octal not hexadecimal right difference i have told you what is octal now how you write hexadecimal constant c in hexadecimal we have sequence of digits preceded by either 0 x or you can say 0 small x
let us suppose i write ah 0 x this is what hexadecimal constant right and see in hexadecimal we use what from 0 to 9 numbers and a to f characters i have told i have written here 0 to 15 but here we use from 0 to9 numbers 10 numbers like right and after that 5 is what alphabets a to f right.
so here you can say a means 10 0 to 9 we use numbers 10 numbers then b like this we are having from 0 to 15 0 to 9 numbers and then 10 to 15 we represent like abcdef so if i write 0x that is also exactly decimal constant if i write like 0 x and 7 If this is also hexadecimal constant but if you write 0 x and suppose i am i am writing 7 g this is not hexadecimal constant because we cannot use g we can use only a to f right so you can say these integer constants are sequence of digits suppose i am writing here one two three four this is also what integer constant but rule or what you cannot write like this 56 comma 100 you cannot write any comma or special character between these constants so this is not valid this is invalid constant integer constant right or if and by default the sign is what plus you can also use sine plus or by default x plus if i write minus 1 to 3 this is also valid so you can write a sign either minus 1 plus if you write like this dollar one two three this is incorrect you cannot use any special character you can you you cannot use any comma you cannot use any spacel ike fifty seven space hundred this is also invalid you cannot use space uh between these sequence of digits this there should not be any space any commas any special character this is valid one two three four or like 56 or five six seven eight this is also valid right so now i hope you got integer constant let us discuss real constants so real constants are also known as floating point constants these are having fractional part like if you uh write 12.56 this is decimal part this is you can say you can say this is what the integer part this is decimal point and this is fractional part so having decimal point these are what real constants so if i write plus this that is also fine if i write minus 50 . 6.02 that is also fine sine can be plus or minus by default sign is plus right but if you write this is invalid there cannot be two decimal points right and you can also represent these uh decimal points or these floating point constant in uh exponential form having mantissa then e then exponent mantissa can be anything like having that decimal point and exponent is always constant right so these are some examples see which one is valid constant or numeric constant or not this one is valid 0x this is also valid This is not valid this one this is not valid because here we have space 0 1 2 this is valid 1 2 3 yes this is valid right and if suppose i write 0x af this is also valid and suppose if I write hash one two three this is invalid you cannot use any special character or known digit character right so these are numeric constant.
Introduction To C programming - 1
Introduction to c programming
The c character set
IDENTIFIERS AND KEYWORDS
Data Types in C (part 2)
Data Types in C....... Today, we will continue our discussion on integer data type. Our outline for today...

-
Ethical Hacking💻 वैसे जिस तेजी से सायबर क्राईमस आजकल बढते जा रहे है . हर बिझनेस ऑर...