Find the answer to your Linux question:
Results 1 to 3 of 3
hi, please can anyone solve my doubt. #include <stdio.h> #include <stdio.h> main() { char names[2][10] = { "ABCDEF", "GHIJKL" }; char **ptr; ptr = names; printf("%s\n", ptr+1); } For this ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    85

    Unhappy Tell me this stuff with Pointers

    hi, please can anyone solve my doubt.
    #include <stdio.h>

    #include <stdio.h>
    main()
    {
    char names[2][10] =
    {
    "ABCDEF",
    "GHIJKL"
    };
    char **ptr;
    ptr = names;
    printf("%s\n", ptr+1);
    }

    For this program, I expected that output should be GHIJKL, But the output is EF.

    and if I change the ptr+1 to ptr[1], then there is a seqfault, what does this mean.

    Thanks in advance.
    Mahesh Gupta.B

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568
    If i'm not wrong - i think it should char* .
    #include <stdio.h>
    main()
    {
    char names[2][10] =
    {
    "ABCDEF",
    "GHIJKL"
    };
    char *ptr;
    ptr = names;
    printf("%s\n",ptr);
    printf("%s\n", ptr + 10);
    }
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    This really looks like school work. Remember that it is not allowed to ask for help solving classwork in the forums!
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...