Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Explain me.... why (http://www.go4expert.com/forums/explain-me-why-t5950/)

mckk84 20Aug2007 18:32

Explain me.... why
 
Code:

#include<stdio.h>
main(int argc, char **argv)
{
        char *ptr1;
        char **ptr2;
        char ***ptr3;
        char arr[10][10];
        ptr1=arr;
        ptr2=arr;
        ptr3=arr;
}


why i'm getting warnings for all the assignments.... which assignment is correct.. and why.... please

DaWei 20Aug2007 18:35

Re: Explain me.... why
 
You want free help? Don't be rude. Read this.

shabbir 20Aug2007 20:52

Re: Explain me.... why
 
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

seeguna 21Aug2007 10:44

Re: Explain me.... why
 
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.........


All times are GMT +5.5. The time now is 14:25.