Advance C++

1. Computer Programming 2. History of Prog.Language 3. Introduction to C++ 4. OOPS 5. Features of OOPS 6. Evolution of C++ 7. Features of C++ 8. Starting Turbo C++ 9. C++ Tokens 10. Basic requirment of C++ 11. Comments 12. My First Program in C++ 13. Line Break 14. C++ Escape Sequence 15. Constants or Literals 16. Variable in C++ 17. Data Types in C++ 18. Basic/Fundamental/Built-in data types 19. User defined data types 20. Derived data types 21. Range of data types in C++ 22. Declare Variables 23. Reserved Key Words 24. cout<< 25. cin>> 26. Prg.to print sum & average 27. Area & Perimeter of Rectangle 28. Area Circumference of Circle 29. Prg. for Area of Triangle 30. Prg.for Simple Calculator 31. Prg.for Arithmetic operators on char variables 32. Calculate Cubic feet & Gallons of water tank 33. setw(n) function 34. setprecision(n) function 35. Operators in C++ 36. Ex. Of Operators 37. Chained and embedded statement 38. C++ prg. to convert farenheit to centigrade/celsius 39. C++ prg. to calculate Area and third side of triangle 40. C++ prg. to solve quadratic equation 41. C++ prg. to solve simultaneous equations 42. C++ prg. for Unary pre and post increment and decrement 43. C++ prg. for reverse a two digit number 44. C++ prg. for Swap two Numbers 45. Hierarchy of operator 46. If Statement 47. C++ prg. for print larger no of two. 48. if..else statement 49. C++ Prg. to print larger no using if..else. 50. C++ Prg. to check divisibility 51. C++ prg. to check leap year 52. C++ prg.to check triangle 53. Prg.to check Equilateral, Isosecles, Scalene triangle 54. Prg.to Calculate Coefficients of quadratic equation 55. C++ if. Else if program example 56. for. . . loop statement 57. prg.to print series using for..loop 58. Prg.to check divisibility 59. prg.to print sum of series 60. C++ prg.for Sum of Factorial 61. C++ prg.to add each digit 62. C++ prg.to print table for that number 63. C++ prg.to print ASCII chart for upper and Lower case 64. C++ prg.to print largest no and smallest no of all. 65. C++ prg.to print no valid or not and print the no. of days 66. C++ prg.to print the distance covered in every 5 seconds 67. C++ prg.to show the distance covered by airplane in the intervals of 20 seconds 68. C++ prg.to print Fibonacci seriess 69. C++ prg.to print factors, gcd and lcm 70. C++ prg.to print four digit perfect squares 71. C++ prg.to calculates the sine of the angle 72. C++ prg.to calculate simple and compound interest 73. C++ prg.to calculate simple and compound interest 74. Points to keep in mind for pyramid 75. C++ Pyramid Prg. Example for Type1 76. C++ Pyramid Prg. Example for Type2 77. C++ Pyramid Prg. Example for Type3 78. C++ Pyramid Prg. Example for Type4 79. C++ Pyramid Prg. Example for Type5 80. C++ prg.to fill screen 81. prg.for largest/smallest no 82. prg.to print nos i,j,k,l such that i 83. while loop statement 84. prg.to print GCD and LCM using while 85. C++ prg.for Prime numbers 86. C++ prg. to check whether a number is palindrome or not 87. C++ prg. to print maximum and minimum number 88. C++ prg. to print Reverse no 89. C++ prg. to calculate factorial using while loop 90. C++ prg. for Armstrong number 91. do. . While statement 92. goto statement 93. break & continue statement 94. switch,case,default statement 95. C++ prg. to enter month number and print month in character 96. C++ prg. to enter character and check is it Vowel or not 97. C++ prg. to implement a calculator using switch case 98. C++ prg. to calculate sine,cosine or tangent of the angle using switch case 99. Array in C++ 100. Declaring Single Dimensional Array in C++ 101. C++ prg.to print nos in original and reverse sequence using Array 102. Ascending/Descending order 103. C++ prg.to search no in Array 104. Diff. between Linear and Binary Serach in Array 105. C++ prg.to rotate an array of n numbers to the right by 1. 106. C++ prg.to Rotate an Array to the left by 1 107. C++ prg.to insert element in the array 108. C++ prg.to delete element in the array 109. Double Dimension Array in C++ 110. C++ prg.to Enter and print using Double Dimensional Array 111. C++ prg.to input a matrix and print it using two dimensional arrays 112. C++ prg.to enter a matrix and print its transpose 113. C++ prg.to multiply 2 matrices 114. C++ prg.to multiply 3 matrices 115. C++ prg.to print a pascal triangle with / without Array 116. String in C++ 117. C++ prg. to print String with spaces 118. C++ prg.to print string in reverse 119. C++ prg.to count A,E,I,O,U vowel 120. C++ prg.to enter a string and encode it 121. C++ prg.to enter a string with spaces and convert string in capital 122. C++ prg. to enter a character and print consonant or vowel 123. C++ prg. for string with spaces 124. C++ prg. for string sorting in ascending order 125. C++ prg. print & Arrange them in order of Title 126. C++ prg. to check whether a string is palindrome or not 127. Function( ) in C++ 128. What is Function Prototyping or Prototyes? 129. C++ prg. to print max number using function 130. C++ Function program examples 131. C++ Prg. to add 2 integers,floats and strings 132. C++ Examples of Function 133. C++ function to print Prime or Fibonicca number 134. C++ prg. to enter string, remove the space and print it 135. C++ prg. to enter number and check it is Palindrome or not 136. C++ prg. to convert positive integer to Binary number 137. C++ function examples 138. Recursive functions 139. General Purpose Programs 140. Loan & EMI calculation prg. 141. C++ Table print prg. 142. lower to UPPER case prg. 143. Age Distribution prg. 144. Bank note calculation prg. 145. Simple Depreciation prg. 146. Reducing bal.Depreciation prg. 147. C++ company manufactures prg. 148. Marksheet prg. 149. Income Tax prg. 150. Time calculator prg. 151. Distance converter prg. 152. Volume Air Calculation prg. 153. Time to fill Water Tank prg. 154. Salary Calculation prg. 155. Total Sale Calculation prg. 156. Male/Female pecentage prg. 157. Library Rent prg. 158. Office Expance prg. 159. Total Salary Calculation prg. 160. Profit or Loss prg. 161. Total Profit/Loss prg. 162. C++ prg. to Convert Amt to Word. 163. # define directive 164. The # undef DIRECTIVE 165. SCOPE RULES AND STORAGE CLASSES 166. Structures 167. C++ structure program to print result based on merit 168. C++ prg.for entry and search within structure 169. C++ prg.for sort the books by author and name of books 170. C++ prg.for Sort employee in descending order of their salary 171. C++ prg. to write structure student, sort it with marks and then name 172. Pointer to the structure 173. Unions 174. Pointers 175. Classes 176. C++ prg. insert,sort,delete,display and search an element in an array using class 177. C++ prg. to add,subtract,multiply and divide two numbers by using inline functions 178. C++ prg. to add,subtract,multiply and divide two numbers 179. C++ prg. to concatenate two string using forward declaration of member functions 180. C++ prg.find its mean,median,standard deviation. 181. Inline functions 182. Objects 183. Access specifiers 184. C++ prg. Example to pass object as parameter 185. C++ Returning object from a function 186. Friend functions 187. C++ Prg.to swap the values of two variables using friend functions 188. C++ Prg. use friend functions which accepts two arrays and merges them and sorts them 189. Friend class 190. Static members 191. Static functions 192. Constructor and destructor 193. Parameterized constructors 194. Dynamic allocation of memory 195. Copy Constructor 196. Inline constructors 197. Constructor overloading 198. Destructors 199. Polymorphism 200. Operator overloading 201. Inheritance 202. C++ Single inheritance 203. C++ Multiple inheritance 204. C++ Multilevel Inheritance 205. C++ Hierarchical inheritance 206. C++ Hybrid inheritance 207. C++ Multipath inheritance 208. Virtual functions 209. Concrete derived class 210. File Handling 211. Read contents from one file and paste it in other file 212. C++ Interview Part1 213. C++ Interview Part2 214. C++ Interview Part3 215. C++ Interview Part4 216. C++ Interview Part5 217. C++ Interview Part6 218. C++ Interview Part7 219. C++ Interview Part8 220. C++ Interview Part9 221. C++ Interview Part10 222. C++ Interview Part11 223. C++ Interview Part11
Pr.Pg Next Pg

Pointers tutorials

  • When a variable is declared, three fundamental attributes are associated with it: its name,its type and its address in memory.

  • For example the declaration

int n;

  • associates the name n,the type int, and the address of same location in memory where the value of n is to be stored.

  • Suppose that address is 0x125639. Then we can visualize n like this

 

cpp pointer example

 

  • The box represents the variable's storage location in memory. The variable's name is on the left of the box, the variable’s address is above the box, and the variable’s type is below the box.

  • If the value of the variable is known, then it is shown inside the box:

 

cpp pointer example

 

  • The value of a variable is accessed by means of its name. For example, we can print the value of n with the statement

cout <<n;

 

  • The address of a variable is accessed by means of the address operator &. For example, we can print the address of n with the statement

cout<< &n;

 

  • The address operator & “operates” on the variables’s name to produce its address.

 

Pointer declarartion

  • Pointer variables, like all other variables, must be declared before they may be used in a program.

  • The interpretation of a pointer declaration is somewhat different, however, than the interpretation of other variable declarations.

  • When a pointer variable is declared, the variable name must be preceded by an asterisk(*).

  • This identifies the fact that the variable is a pointer. The data type that appears in the declaration refers to the object of the pointer i.e. the data item that is stored in the address represented by the pointer, rather than the pointer itself.

  • Thus a pointer declaration is written as:

 

data_type *variable_name;

 

C++ Program to print the memory address of an integer variable

Sam Madam

//WAP to print the memory address of an integer variable

#include <iostream.h>

#include <conio.h>

void main()

{

int n=13;

cout <<endl<<”Value of n = ”<<n;

cout <<endl<<”Memory address of n = ”<<&n;

getch();

}

Output

Value of n =13

Memory address of n = 0x237723fa

 

C++ Program to print the memory address of a float variable

Sam Madam

//WAP to print the memory address of a float variable

#include <iostream.h>

#include <conio.h>

void main()

{

float n=13.5;

cout <<endl<<”Value of n = ”<<n;

cout <<endl<<”Memory address of n = ”<<&n;

getch();

}

Output

Value of n =13.5

Memory address of n = 0x234921fa

 

Assigning the memory address of a variable to another pointer variable

  • The process of assigning the memory address of a variable to another pointer variable is known as giving the reference to another variable.

  • A reference is an alias. It is declared by using the reference operator & appended to the reference’s type. & is an unary operator. The reference operator & returns the memory address of the variable to which it is applied.

  • This type of the variable that stores an ddress is called a pointer. If the variable has type int, then the pointer variable must have type “pointer to int” , denoted by int*.

 

C++ Program to study a pointer variable pointing to an integer variable

Sam Madam

//WAP to study a pointer variable pointing to an integer variable

#include <iostream.h>

#include <conio.h>

void main()

{

int *p,x=10;

cout <<x<<endl<<" address of x "<<&x<<endl;

p=&x;

*p=100;

cout <<"p= "<<p<<endl<<"x="<<x;

getch();

}

Output

10

address of x 0x237723fa

p= 0x237723fa

x=100

 

C++ Program to add two integers and print the memory addresses of the two operands as well as its result

Sam Madam

/*WAP to add two integers and print the memory addresses of the two operands as well as its result

*/

#include <iostream.h>

#include <conio.h>

void main()

{

int a,b,s;

cout <<"Enter 2 nos ";

cin>>a>>b;

s=a+b;

cout <<"\nThe sum is "<<s;

cout <<"\nMemory address of a is "<<&a;

cout <<"\nMemory address of b is "<<&b;

cout <<"\nMemory address of s is "<<&s;

getch();

}

Output

Enter 2 nos 2 3

 

The sum is 5

Memory address of a is 0x23df2550

Memory address of b is 0x23df254e

Memory address of s is 0x23df254c

 

Double pointer

  • As the name suggests double pointer points to a pointer variable storing the memory address of the pointer variable.

  • A double pointer is represented by **.

  • For example we illustrate double pointer as

int **p;

 

C++ Program to illustrate a double pointer

Sam Madam

//WAP to illustrate a double pointer

#include <iostream.h>

#include <conio.h>

void main()

{

int a=13;

int *p;

int **dp; //pointer to pointer p

p=&a;

dp=&p;

cout <<endl<<"Value of integer a : "<<a;

cout <<endl<<"Memory address of integer a : "<<&a;

cout <<endl<<"Value of pointer p pointing to integer a : "<<*p;

cout <<endl<<"Memory address of pointer p holding the address of integer a : "<<&dp;

cout <<endl<<"Value of double pointer dp : "<<**dp;

getch();

}

Output

Value of integer a : 13

Memory address of integer a : 0x2377248a

Value of pointer p pointing to integer a : 13

Memory address of pointer p holding the address of integer a : 0x23772482

Value of double pointer dp : 13

 

Passing pointers to functions

  • Pointers are often passed to a function as aruments. This allows data items within the calling portion of the program to be accessed by the function, altered within the function, and then returned to the calling portion of the program in altered form. We refer to this as passing arguments by reference.

  • When an argument is passed by value, the data item is copied to the function,. Thus any alteration made to the data item within the function is not carried over into the calling routine.

  • When an argument is passed by reference, however the address of a data item is passed to the function.

  • The contents of that address can be accessed freely, either within the function or within the calling routine.

  • Moreover, any change that is made to the data item will be recognized in both the function and th calling routine.
    Thus, the use of a pointer as a function argument permits the corresponding data item to be altered globally from within the function.

  • When pointers are used as arguments to a function, some care is required with the formal argument declaraons within the function.

  • Specifically, the formal arguments that are pointers must each be preceded by an asterisk. Also, if a function declaration is included in the calling portion of the program, the data type of each argument that corresponds to a pointer must b followed by an asterisk.

 

C++ Program to show pointers to functions

Sam Madam

/* WAP to show pointers to functions

 

#include <iostream.h>

#include <conio.h>

 

void function1 (int a, int b)

{

a=0;

b=0;

cout <<”\nValue of a in function1= ”<<a;

cout <<”\nValue of b = ”<<b;

}

 

void function2(int *x,int *y)

{

*x=0;

*y=0;

cout <<”\n Value of b in function2= ”<<x;

cout <<”\n Value of b in function2= ”<<y;

}

void main()

{

int a=3,b=2;

cout <<endl<<”Value of a in main = ”<<a;

cout <<endl<<”Value of b in main = ”<<b;

function1(a,b);

function2(a,b);

getch();

}

Output

Value of a in main = 3

Value of b in main = 2

 

Value of a in function1= 0

Value of b in function1= 0

 

Value of a in function2= 3

Value of b in function2= 2

 

Pr.Pg border                                              Next Pg