Types of Constants:
1. String constants: String constants consist of alphanumeric characters within double quotes. Eg:”abc123”,”sachin”.
2. Integer constants: Integer constants are those which are used to store whole numbers that is numbers without decimal points. E.g.: 100,10,7 etc.
3. Character constants: Character constants are those which used to store characters are represented within single quotes. It may be a character, alphabet, single digit. E.g.: ‘7’, ‘i’ etc.
4. Boolean constants: Boolean constants represent only two values true or false.
5. Floating point constants (Real Constants): Floating point constants are used to store numbers having decimal points or i.e. real numbers. E.g.: 9.125, 7.356.
What are the different types of Constants?
What is variable and constant?
Variables are used to store the values depending upon its data type. We can change the value of the variable at any time during the execution of a program.
Constants are those whose values remain same and cannot be changed at run time. There are three types of Constants:
1. String constants
2. Numeric constants
3. Character constants
What is an Identifier?
Identifier is the name given to the variable, function, array, structure etc.
There are certain rules which an identifier must follow:
1. It should not be a keyword which is available in the language.
2. First character of identifier should be an alphabet or underscore.
3. No other special character is allowed except underscore (_).
4. Both the cases that are upper case and lower case are allowed. An identifier student is not same as STUDENT.
What is Function call?
Function call means calling of a function to execute the statements of the function. A function call contains the name of function and the arguments that are sent to the function. When we call a function control is transferred to that particular function, executes the statements within that function and returns back after executing that function.
Eg:
Void add (int c, int d)
{
Printf (“%d”, c+d);
}
Void main ()
{
Int a=12,b=10;
Add (a,b); //Funtion call
}
What are the diiferent methods of calling Functions?
There are two methods of calling a function:
1. Call by value method
2. Call by reference method
What is Call by value method?
In call by value method values of the variables are send at the time of function call. It makes the copies of variables that are sent to the function because of which any changes made by the function are not reflected in the original variables.
Eg: Program of swapping values of two variables by using call by value method
Void swap (int c,int d)
{
Int temp;
temp=c;
c=d;
d=temp;
}
Void main()
{
int a=10, b=20;
swap(a,b);
printf (“Value of a is %d \n value of b is %d”,a, b);
getch();
}
Output:
Value of a is 10 value of b is 20
What is Call by reference method?
In call by reference method addresses of the variables in memory are send at the time of function call rather than their values. Due to this any changes made by the function are reflected in the original variables.
Eg: Program of swapping values of two variables by using call by reference method
Void swap (int *c,int *d)
{
int temp;
temp=c;
c=d;
d=temp;
}
Void main ()
{
int a=10,b=20;
swap (&a, &b);
printf(“Value of a is %d \n value of b is %d”,a,b);
getch();
}
Output:
Value of a is 20 value of b is 10
What is Function overloading?
Fuction overloading means defining more than one function having same name in a class or defining multiple functions of same name. Function overloading is used to define same name functions that perform similar operations on different data types of arguments and in this way it implements polymorphism because a single function name is used for performing multiple operations. In case of function overloading, compiler calls the different functions by checking their data type, the number of arguments of the functions, their order in the function call and function definition.
E.g. of Function Overloading:
Class area
{
Double ar;
Public:
Void Area(int s)
{
Ar=s*s;
}
Void Area(int l,int b)
{
Ar=l*b;
}
Void Area(float r);
{
Ar=3.142*r*r;
}
What are the Constructors?
Constructors are the member functions of class which have the same name as that of class name and are used to initialize data of class which is also known as member data.
Constructors are basically used to assign values to the variables of class as we cannot assign values to them at the time of their declaration. We do not have to call them as they are called automatically when we create an object of class.
Features of Constructors:
1. Constructors have same name as that of class name.
2. They are basically used to give initial values to the data of class.
3. They are automatically called by the compiler when object of the class is created.
4. We can overload the constructors. Defining multiple constructors in a class is known as Constructor overloading.
Types of Constructors:
1. Default Constructor
2. Parameterized Constructor
3. Copy Constructor
Who invented C++?
C++ Programming Language was invented by “Bjarne Stroustrup” in 1983 at AT&T Bell Laboratories of USA. C++ is similar to C with some additional features. C++ uses features of OOPs like Classes and Objects, Encapsulation, Data hiding, Abstraction, Dynamic Binding, Message Passing etc.