1. Home >
  2. Apps >
  3. Groups >

All about Pointers

Question asked by Manish Goyal in #Coffee Room on Jan 15, 2011
Manish Goyal
Manish Goyal · Jan 15, 2011
Rank A2 - PRO
Let us discuss everything about pointers, starting from basic definition to each and every error that generally occurs while doing programming in c++ through this thread


I am sure it will help a lot of students Posted in: #Coffee Room
Manish Goyal
Manish Goyal · Jan 16, 2011
Rank A2 - PRO
No reply so far

come on guys ,didn't you find any problem while working with pointers?If yes, then share it
sachin bankar
sachin bankar · Jan 20, 2011
Rank D3 - MASTER
Pointer is a variable which holds address of another variable
Ankita Katdare
Ankita Katdare · Jan 20, 2011
Rank A1 - PRO
Thank you Goyal for starting this thread.
Everyone learning C or C++ faces problems with pointers at the beginner level.

Could someone start with explaining the basics of pointers and their various forms?
Deepika Bansal
Deepika Bansal · Jan 20, 2011
Rank B2 - LEADER
Pointers have some relation with with 1D and 2D arrays. I'm quoting the example of a C++ program.
void main()
{
int a[5];    //creating an integer array to store upto 5 integers
cout<This was the case of static sized arrays ie size of the array is known at the compile time. 
eg:- consider the following code-->
//this is okay
const int size=5;   //creating a constant variable
int a[size];

//but this is wrong
int size=5;
int a[size];
so to create dynamic arrays (eg when size has to be known from the user), we make use of pointers as-->
int size;
int *a;   //uninitialized pointer
cout<<"Enter the size of the array: ";
cin>>size;   //got the array size from the user
a=new int[size];  //a can now hold upto 'size' number of variables

//now the elements of 'a' can be accessed in any of the 2 ways discussed above.
Also there is a difference between int a=new int[size]; and int a=new int(size);
int a=new int[size]; will create an array 'a' of size/length='size'.
but int a=new int(size); will create an int variable ie only 2 bytes will be allocated to 'a' whose value or memory content will be='size'.


PS: It's been very long that I've revised my C++ concepts. If anyone finds any error or ambiguity, please do let me know.😀 Will try to post the maximum of my knowledge about pointers.😛

You must log-in or sign-up to reply to this post.

Click to Log-In or Sign-Up