i get two strings
a and b
char *a,*b;
and later put in them some values
can i do
a=b;
i know that strings are arrays and we cant do this because they are defined as const
??
i get two strings
a and b
char *a,*b;
and later put in them some values
can i do
a=b;
i know that strings are arrays and we cant do this because they are defined as const
??
Yes, you can, but if you should depends on the rest of the program code.
i know that in arrays we cant do it because the are defined as constant
so we cant do it in strings
char* is pointer not arrayi know that strings are arrays
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
but we can represent an array as a pointer that decays to the first cell.
so why in arrays we cant do it but in strings we do
??
there are situation where arrays are handled as pointers to the first element.
and there are situations where arrays cannot be handles in a ways pointers can.
you can assign to pointer, you cannot assign to array
is array C-string or not - is irrelevant
you just mixed too approaches to the same object in one statement. This prevents from deciding what part of your statement was wrong
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
what do you mean by "there are situation"
i remember that on this board where i tried to make a copy of an integer array by doing
a=b
and i was told that its impossible because its a constant
so in this case its the same same case but instead integer type pointer i got chat type pointer
so i cant see why it should work
??
Well, a and b were never arrays to begin with, you defined them as pointers. The fact that you "gave them values" is a tad nonspecific, because there are situations where a=b is perfectly legal and safe, situations where it is legal and not safe, and situations where it is not legal.
Arrays are an rvalue in C (like constants are) and it is not legal to associate an array name with another value, any statement that attempts this should result in an error. Pointers as lvalues do not have this restriction. Pointers are values, not objects. For further reading and full understanding you can read C For Smarties: Analyzing Expressions.
Last edited by whiteflags; 03-15-2009 at 02:32 PM.
you cant separate pointers and arrays
they are the same thing
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
so string are arrays and we cant do this
actually size of gives us different result if its a pointer on a signature
because its decays
other wise its the same thing
correct?
C doesn't even have a string type, so as a statement that is wrong and as a question it has no context.so string are arrays and we cant do this