Tuesday, February 14, 2012
What is constant pointer and pointer to the constant?
C/C++ supports read-only declaration of the variable by using const key word. so that it cant be modified/changed later. values will be assined to the const variables at the time of declaration only.
main()Pointer to the Constant: This means a pointer to the constant variable like any other variable. But here the difference is, we cant able change the value of the variable. But we can assign as many pointers as we can.
{
const char a='A'; // declaration n initialization
//a='a'; // Illegal, cant modify the constant variable
}
main()Constant Pointer: This means its a constant pointer and once it is assigned one address and it cant be reassined to another address. But value can be reassigned/changed.
{
char a='A';
const char *ptr = &a; // pointer to the constant
//*ptr='a'; //illegal cant change the constant value
const char *ptr1 = &a; // another pointer to the constant value
}
main()
{
char a='A';
char b='B';
char *const ptr = &a; // pointer to the constant
//ptr = &b; //Illegal another pointer to constant pointer not allowed
*ptr='a'; //legal, can change the value
}
Subscribe to:
Post Comments (Atom)
Popular Posts
-
A universally unique identifier ( UUID ) is an identifier standard used in software construction, standardized by the Open...
-
Recently I started working on Japser Studio professional for my new project Cloud to generate the reports. I was very new to all cloud ...
-
Below is C program for AVL Tree implementation. #include<stdio.h> #include<malloc.h> typedef struct bst { int info; int hei...
-
strcmp is another string library function which is used to compare two strings and returns zero if both strings are same , returns +ve valu...
-
One of the complex operation on binary search tree is deleting a node. Insertion is easy by calling recursive insertion. But deletion wont...
-
We have recently faced one tricky issue in AWS cloud while loading S3 file into Redshift using python. It took almost whole day to inde...
-
Object slicing: when a derived class object is assigned to a base class object. only base class data will be copied from derived class and...
-
We have faced lot of weird issues while loading S3 bucke t files into redshift. I will try to explain all issues what we faced. Before go...
-
Below code is to find the cube root of a given integer number with out using pow math library function. Its very simple and brute force...
-
Recently we faced one issue in reading messages from SQS in AWS cloud where we are processing same message multiple times. This issue we...
No comments:
Post a Comment