?
Solved

C Puzzle (for fun only!)

Posted on 1998-08-18
18
Medium Priority
?
161 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
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.
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

743 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