• 4 months ago
उरण प्रकरणात लव जिहादचा आरोप करणाऱ्या नेत्यांना शर्मिला राज ठाकरेंनी सुनावलं...

Category

🗞
News
Transcript
00:00let us talk about variables let us see how we can declare them I have already
00:03kept a skeleton of a program ready here I will declare some variable let us say
00:08I want to say integer X okay this is valid integer X 1 this is also valid
00:14integer 1 X and see here's a prompt I'm getting an error message that expected
00:25unqualified ID see this is an unqualified ID you cannot have a number
00:29before a name the first letter must be a alphabet let us try underscore with it
00:36allow then integer I will say capital X let us see whether it will allow or not
00:43these are warnings that I have declared the variables but I am not using them so
00:48it's not a issue really I'm not using them I have just
00:52declared them so it's a warning showing you that maybe that unnecessary variable
00:56you have declared so try to remove it if you if you are not using it but no we
01:01are just testing it let us leave it ignore these messages here you can
01:05observe I have taken a small letter X and capital letter X yes both are valid
01:09because those are treated as two different variables then what is better
01:14is if I am having a integer type variable for storing a roll number then
01:20better take it as roll number this will be more readable and is more meaningful
01:26or else I can also write a roll underscore number this was the method
01:31used in C language but in C++ we follow camel notations that is we make the
01:37first letter of every alphabet as capital so this is how we can have valid
01:43names of the variables let me try one more thing integer if can I take a
01:47keyword if is also a keyword in C++ programming but I cannot use it as a
01:53variable name again it is expected unqualified ID so this is unqualified ID
01:59so you cannot use keywords as variable names can I use the class name that is
02:06available in C++ int string yes I can use it because that is not a part of
02:12compiler it's a library class available so it means I want to use that name yes
02:18you can use it these are variables are declared now let us look at some
02:23literals let us see how to declare the variables and also how to initialize
02:28them I am having an integer variable a and to this I want to assign value 10
02:34let us display this value and C and L yes I can assign the value like this let
02:42me run the program and see I have assigned the value 10 there yeah 10 is
02:48displayed here this is a integer literal I will write 0 in the beginning
02:53so this becomes a octal literal let us try to print and see what is the output
02:58see in the decimal form it is 8 if you convert this octal number into decimal
03:04the result is 8 okay I will use 0 X and 1 0 so this will be a hexadecimal
03:11constant let us run and see 1 0 is a 16 in hexadecimal form so yes so that's how
03:20we can initialize any type of literals these are all different integer
03:24literals now can I assign value 10 like this let us see the method yes we can
03:31initialize a variable by using brackets and even I can use assignment before
03:38this one this also works or I can use flower brackets or braces for enclosing
03:47the value this is called as array initializer it is just like initializing
03:51an array we are initializing a variable this is also valid this is the part of
03:56modern C++ where you can initialize the variables using brackets that is array
04:01initializer or without assignment also it can be done it also works perfectly
04:09that's it these are the ways the variables can initialize now let us look
04:14at different data types if I have a character type variable a and in this I
04:19will assign value a so this is how a character literal is assigned let us
04:25print and see it is displaying a now instead of a can I use 65 if I assign 65
04:35here let us see what will happen yes 65 also can be assigned I will print this
04:40as I have assigned 65 so ASCII code for a so a is printed here then can I use
04:51octal number 0 X 4 1 let me try with this number can I use hexadecimal number
05:04let us try this one 4 1 this is the hexadecimal code for 65 yeah again it is
05:11a now to this character can I assign a float value let us see what happens
05:1712.5 character 12.5 yes this is working and it is trying to display a character
05:27so there is no valid character for the value 12 so it's not appearing not
05:32showing anything it will truncate this 0.5 and take just 12 I will try to give
05:3865 and see what happens yes it is printing a see here compiler is not
05:48giving an error message that a float value cannot be assigned to a character
05:52type variable so that's it compiler is ignoring it and it is called as coercion
05:58if a value is internally converted into a required data type so a float value is
06:06converted to character and it is done implicitly so it is called as coercion
06:11let me try a float type of variable float
06:19float a and to this I will assign the value one twenty three point five six
06:26yes I can use this value it's working can I use this one e2 yes into hundred
06:44it has done because two is ten square that is hundred it is working so e minus
06:52two yes it's working divided by hundred that is 1.23 so even using scientific
07:01notation we can mention float values it's better you write F here to show
07:06that as a float constant so that's it these are the basic things how a
07:10variable can be declared and how we can assign some constants to them let us try
07:17a string type of value string type of literals when we have a string type
07:22literal we have to mention the value in double quotes so I am giving a message
07:27hello let us try this yeah it's working see string is not a primitive data type
07:39but there is a class available in standard namespace so we can use this as
07:44a object so we can create objects and use it that's it about the variables and
07:52their literals you can try it out on your machine and see you can play around
07:59with these values so this will give you some good this will give you some good
08:03idea about the data types and how we can assign the values spend some time
08:08practicing this

Recommended