Im going to be taking Intro to C in the fall so I have decided to read up on the textbook and learn how to program before the semester starts. I'm having a little problem, here's the trouble maker:
potr1 = &goodarray[0];
potr2 = &goodarray;
for some reason potr2 gets assigned the value of the &goodarray[0]instead of the &goodarray itself.. I have verified this by printfing both of them and they come up the same number. Im using DevC++ and Im pretty sure I just need to find a better compiler, but am I doing something wrong?
Name:
Anonymous2011-07-19 2:40
>>1
What are you trying to do exactly? What datatype are those variables?
>>6 The name of an array evaluates to a pointer to the first element of the array, as >>3,4 pointed out.
That's a big no you dumbass. The person that gave the response never said that. You just incorrectly assumed it. For further clarification, please refer to section 5.3 in the second edition of "The C Programming Language" by K & R.
>>23
That >>6 doesn't understand the relationship between a pointer and an array in C.
Name:
Anonymous2011-07-20 23:11
arrays and pointers differ in size
Name:
Anonymous2011-07-20 23:32
Im going to be taking it up the ass in the fall so I have decided to read up on the textbook and learn how to anus-spread before the semester starts. I'm having a little problem, here's the trouble maker:
finger1 = &anus[0];
finger2 = &anus;
for some reason finger2 gets inserted with the value of the &anus[0]instead of the &anus itself.. I have verified this by inserting both of them and they come up the same rectal wall. Im using AstroGlide++ and Im pretty sure I just need to find a better partner, but am I doing something wrong?
>>26
How's that? Please explain how The name of an array evaluates to a pointer to the first element of the array
is not true.
Since you referred me to 5.3 in K&R2, I will quote it for you: Since the name of an array is a synonym for the location of the initial element, the assignment pa=&a[0] can also be written as
Also you stupid shit, pa if of type int * as opposed to something like say int[10].
Name:
tourettes syndrome2011-07-21 1:43
>>30,31 Would foo evaluate to a pointer to the first element of this array?
Um... Why, yes, it would.
Am I alone in thinking this guy is insane? Holy moley.
I'm not sure what your deal is, besides being autismal as fuck, so I will just leave you with this: http://codepad.org/z3aQna6H
Name:
Anonymous2011-07-21 2:03
>29-32 The name of an array evaluates to a pointer to the first element of the array
Technically, the name of the array evaluates to pointer to an array which has the same value as the pointer to its first element. It has the same value but it's of a different type. In this case foo == &foo but sizeof(foo) != sizeof(&foo). Matters when doing memcpys and shit.
This whole shit about ``the name of an array'' is _still_ irrelevant to this discussion in particular, and, furthermore, to _any_ C-related discussion in general.
Get over it.
>>44 I really hope that you aren't the same person that said the following..
I'm not.
In other other words, one is an array of 10 char objects and the other is a pointer.
Guess what: No shit, Sherlock. Just look up their fucking declarations, cause that's how (explicit) statically typed languages work...
Name:
Anonymous2011-07-21 12:31
The pointer to the first object in an array and a pointer to the array itself is the same value in C (and in most languages I think). In fact, there's no real distinction between writing to an array and writing to a memory address that's probably being used by a high level process in that exact moment.
And yes, if that fills your heart with dread, you should be scared. Be afraid. Be very afraid.
Name:
Anonymous2011-07-21 13:07
>>46
No, because one points to an array which an unmodifiable lvalue, and the other points to an array element.
>>49
This is getting boring, dude. I've pointed out your stupidity several times now and it _still_ didn't shut you up. I suggest you d/l a copy of the C std and study it for the next, say, 5 years. Maybe it dawns on you, but prolly it won't.
Also, learn how to use code tags, for fuck's sake. Can't even take you serious.
>>50
You don't know what you are talking about you stupid hourly worker. Unlike you, I actually do this kind of stuff for a living. Now get lost you fucking minimum wage bitch.
char (*q)[10] = &a; // a pointer to the array itself
Something like char (*q)[10] is a pointer to char[10]. In other words, it doesn't point to the array itself. The fact that you keep insisting that this is the array itself makes you that much dumber.
Name:
Anonymous2011-07-21 15:58
>>54
Okay, I work Kodak Gallery on Hollis Street here in emeryville. You are more than welcome to come up here and say that to my face you stupid hourly worker bitch.
>>66
Uhm, so what? This has nothing to do with this discussion, at all.
Name:
Anonymous2011-07-21 16:27
>>67
I was just rebutting someone who clearly doesn't deal with this kind of stuff for a living. Presumably the person doesn't have the mental capacity to do anything beyond general labor jobs.
>>66
Anyways. Your misconceptions seem to come from the failure to realize that there basically are 3 "contexts" in which expressions are evaluated in C:
(1) object context
(2) value context
(3) void context
>>69
Huh? I'm not the one that made the following idiotic statement...
char (*q)[10] = &a; // a pointer to the array itself
Besides you fucking mental midget, the object context and the value context bear no real relation to what we are talking about. The fact that you think it might makes you that much dumber
Anyways. Your misconceptions seem to come from the failure to realize that there basically are 3 "contexts" in which expressions are evaluated
First off, there are only two contexts defined by the standard. The fact that you thin there might be three makes you a fucking dumb nigger. On top of that, those evaluations hold for expressions, expressions statements, and statements.
>>70
Right - you're the one who made the following statement: &a points to the first object in the array named 'a'.
HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA
Unlike yours, my statement is perfectly fine and correct.
And what really bears no relation to the discussion at hand is the fact that expressions with array type are unmodifiable lvalues, BTW.
>>79 One could basically say, that I've altered the array _itself_.
No. You're still confusing an *array* with the *array element* in C. In this case, you are manipulating the *array element* which is part of the *array*. However, at no point and time do you actually manipulate the actual array itself.
Name:
Anonymous2011-07-21 17:41
I can't believe we have a tripfag this stupid hanging around.
Hey if I have int x[10];, what does x evaluate to?
>>86
In strict computer science terms? Or in your retarded blue collar worker terms? Either way, the evaluation only bears relevance when something like &a gets evaluated to a number at runtime. As opposed to say, compile time.
Name:
Anonymous2011-07-21 19:06
>>86
And if you really think the evaluation of statement
int a[10];
has any impact on your misinformed notions about the relationship between an array elmetn and a pointer in C, then you really are that fucking stupid.
SICP is mush-brained drivel by a pseudo-intellectual cockpouch. It's right up there with TAOCP and K&R as things that idiots read to make people think they're smart.
printf("%s\n", array); //not useful to the discussion
return 0; //slower than void return.
}
>>1
yep, arrays are fancy addressing systems, your mistake is that you believe that the array is a pointer itself, and has some location in memory. The fact is, however, that an array IS simply an address. therefore the statement: potr2 = &goodarray;
Is simply you trying to get the address of an address. Your compiler gave you a break by not raping you in the eye and telling you to kill yourself; but you were still being retarded. The part that gets me is that you were so blindly confident that an array was a pointer that you started this thread.