Explain me.... why

Discussion in 'C' started by mckk84, Aug 20, 2007.

  1. mckk84

    mckk84 New Member

    Joined:
    Jun 30, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include<stdio.h>
    main(int argc, char **argv)
    {
            char *ptr1;
            char **ptr2;
            char ***ptr3;
            char arr[10][10];
            ptr1=arr;
            [B]ptr2=arr;[/B]
            ptr3=arr;
    }

    why i'm getting warnings for all the assignments.... which assignment is correct.. and why.... please
     
    Last edited by a moderator: Aug 20, 2007
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    You want free help? Don't be rude. Read this.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I am not sure why you are getting warning but I get errors.

    Code:
    error C2440: '=' : cannot convert from 'char [10][10]' to 'char *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    error C2440: '=' : cannot convert from 'char [10][10]' to 'char ** '
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    error C2440: '=' : cannot convert from 'char [10][10]' to 'char ***  '
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    and the warning is for the main not returning anything.
    Code:
    warning C4508: 'main' : function should return a value; 'void' return type assumed
     
  4. seeguna

    seeguna New Member

    Joined:
    Jun 20, 2007
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Technical Consultant
    Location:
    Chennai
    It was surprised to get u warnings instead of errors.


    Anyhave , I think that u r trying to point a 2D character array using pointer variable....
    To attained it just use
    ptr1=arr[0];(i.e enough)

    ptr2 and ptr3 are not at all needed.........
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice