All about Pointers

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

Replies

  • Manish Goyal
    Manish Goyal
    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
    Pointer is a variable which holds address of another variable
  • Ankita Katdare
    Ankita Katdare
    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
    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 are reading an archived discussion.

Related Posts

[FONT="]Elements of a Process Control System[/FONT][FONT="][/FONT] INTRODUCTION -The term automatic process control came into wide use when people learned to adapt automatic regulatory procedures to manufacture products or process material...
hey friends, i got a doubt some where i listened as grounding means connecting to a metal is it right if so why we are using the metal from the...
Yes its up All in events for Mechanical Engineers at PSG Tech Just check here PRAYATNA '11
KRIYA, the brainchild of the Students Union, PSG Tech, is the conglomeration of the elite brains across the Indian heartland. It is the biggest conflux of students, industry and academia...
in simple rankine cycle the the hot steam from the boiler is passes through the turbine to produce shaft work.. after this that steam get condensed which still contains good...