Thread: c++ question

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    183

    Question c++ question

    hello .
    I am new here and sorry my English isn't good . I know c++ language alittle and I think in some parts of it I am good , hope I can help you in them .
    I have a question about pointers :
    in c++ language if we have :
    . int a[10];
    . int *p;
    . p=a;
    we can say :
    . a[i]=*(p+i)
    my question is :
    if we have a[i][j] how we can define it with pointer .
    . a[i] = *(p+i)
    . a[i][j] = ?


    tnx

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Code:
    int main ( ) {
        int a[10] = { 0 };
        int *pa = a;
    
        int b[5][10] = { 0 };
        int (*pb)[10] = b;
    
        a[5] = 123;
        printf( "%d\n", *(pa+5) );
    
        b[2][4] = 321;
        printf( "%d\n", *(*(pb+2)+4) );
    
        return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    183

    Smile

    thank alot salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM