Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


C++ Programming Code Examples

Learn C++ Language

Pointers in C++ Programming Language

Pointers in C++ Language
The pointer in C++ language is a variable, it is also known as locator or indicator that points to an address of a value. In C++, a pointer refers to a variable that holds the address of another variable. Like regular variables, pointers have a data type. For example, a pointer of type integer can hold the address of a variable of type integer. A pointer of character type can hold the address of a variable of character type. You should see a pointer as a symbolic representation of a memory address. With pointers, programs can simulate call-by-reference. They can also create and manipulate dynamic data structures. In C++, a pointer variable refers to a variable pointing to a specific address in a memory pointed by another variable.
Syntax for Pointers in C++
int *ip; // pointer to an integer double *dp; // pointer to a double float *fp; // pointer to a float char *ch // pointer to character
• Pointer reduces the code and improves the performance, it is used to retrieving strings, trees etc. and used with arrays, structures and functions. • We can return multiple values from function using pointer. • It makes you able to access any memory location in the computer's memory. Dynamic memory allocation: In c language, we can dynamically allocate memory using malloc() and calloc() functions where pointer is used. Arrays, Functions and Structures: Pointers in C language are widely used in arrays, functions and structures. It reduces the code and improves the performance. & (ampersand sign): Address operator - Determine the address of a variable. * (asterisk sign): Indirection operator - Access the value of an address. The pointer in C++ language can be declared using * (asterisk symbol).
/* pointer is a variable in C++ that holds the address of another variable */ #include <iostream> using namespace std; int main () { int var = 20; // actual variable declaration. int *ip; // pointer variable ip = &var; // store address of var in pointer variable cout << "Value of var variable: "; cout << var << endl; // print the address stored in ip pointer variable cout << "Address stored in ip variable: "; cout << ip << endl; // access the value at the address available in pointer cout << "Value of *ip variable: "; cout << *ip << endl; return 0; }



The "expressions" are evaluated in order; if an expressionis true, the 'statement' or 'block of statement' associated with it is executed, and this terminates the whole chain. The Code for





This is a C++ Program to find 'Prime number' between the given range using 'Wheel Seive' method. "Wheel Factorization" is a graphical method for manually performing preliminary