Solved

C Puzzle (for fun only!)

Posted on 1998-08-18
18
158 Views
Last Modified: 2010-04-15
     register int x[2];
is a valid declaration.  Only one operation on x is
legal, but what is it?

0
Comment
Question by:JYoungman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 4
  • +4
18 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1252137
Not sure the question is very clear - you mean the whole of x

Problem is you can't do address of - &

sizeof ??
0
 
LVL 5

Expert Comment

by:ecw
ID: 1252138
sizeof(x)
0
 
LVL 2

Author Comment

by:JYoungman
ID: 1252139
Yep.  Maybe that one was too easy :-)

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:alexo
ID: 1252140
Keep em comming...
0
 
LVL 1

Expert Comment

by:newexpert
ID: 1252141
But remeber register is only a request.  So if somehow computer decide not to grand what's requested then ...
0
 
LVL 1

Expert Comment

by:newexpert
ID: 1252142
The following 4 operations are also valid: x[0], x[1], 1[x], 0[x]
although you can argue they are too similar to be 4.
0
 
LVL 1

Expert Comment

by:newexpert
ID: 1252143
yuk, they still made implicit reference to the address.
0
 
LVL 1

Expert Comment

by:payn
ID: 1252144
Isn't *x valid?
0
 
LVL 1

Expert Comment

by:newexpert
ID: 1252145
Nope.  Remember you can't directly or indirectly refer to x's address, so how can you dereference x's address?

The only other pseudo-operation is #x, which gets interpreted as "x" by compiler.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1252146
#x is textual substitution done py the preprocessor befor the compiler gets to look at the code.  It has no relation to the x variable.
0
 
LVL 2

Author Comment

by:JYoungman
ID: 1252147
Anybody want to answer this so we can convert it to a PAQ?

0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1252148
"But remeber register is only a request.  So if somehow computer decide not to grand [grant ?] what's requested then ..."
It can but the syntax rules for register variables still apply AFAIK
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 0 total points
ID: 1252149
Lock for PAQ:
sizeof is the only operation that works of the whole of x

e.g.
int y = sizeof(x) ;

0
 
LVL 11

Expert Comment

by:alexo
ID: 1252150
>> It can but the syntax rules for register variables still apply AFAIK
Correct.  Same as the C++ "inline" request.
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1252151
sizeof is OK.
What if you are using a C++ compiler? Won't the address-of(&) work?
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1252152
pagladasu - not on a register variable
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1252153
Answers2000-The address-of operator works on register variable in C++ - try it out with the VC++ compiler yourself and see. Also please check out the latest book on the C++ programming language by Bjarne Stroustrup.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1252154
Hmmm...  Just checked the ARM.  He's right, it is permissible in C++.
Live and learn...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question