Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C Puzzle (for fun only!)

Posted on 1998-08-18
18
Medium Priority
?
162 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

610 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