473,466 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Programming Puzzle

I found these questions on a web site and wish to share with all of u
out there,Can SomeOne Solve these Porgramming puzzles.
Programming Puzzles

Some companies certainly ask for these things. Specially Microsoft.
Here are my favorite puzzles. Don't send me emails asking for the
solutions.

Q1 Write a "Hello World" program in 'C' without using a semicolon.
Q2 Write a C++ program without using any loop (if, for, while etc) to
print numbers from 1 to 100 and 100 to 1;
Q3 C/C++ : Exchange two numbers without using a temporary variable.
Q4 C/C++ : Find if the given number is a power of 2.
Q5 C/C++ : Multiply x by 7 without using multiplication (*) operator.
Q6 C/C++ : Write a function in different ways that will return f(7) =
4 and f(4) = 7
Q7 Remove duplicates in array
Q8 Finding if there is any loop inside linked list.
Q9 Remove duplicates in an no key access database without using an
array
Q10 Write a program whose printed output is an exact copy of the
source. Needless to say, merely echoing the actual source file is not
allowed.
Q11 From a 'pool' of numbers (four '1's, four '2's .... four '6's),
each player selects a number and adds it to the total. Once a number
is used, it must be removed from the pool. The winner is the person
whose number makes the total equal 31 exactly.
Q12 Swap two numbers without using a third variable.
Given an array (group) of numbers write all the possible sub groups of
this group.
Q14 Convert (integer) number in binary without loops.

Q3,12 are similar , Q7 is simple & I know there answer For the Rest
please Help
Wiating for reply.
Nov 14 '05
271 19858
Irrwahn Grausewitz wrote:

Da*****@cern.ch (Dan Pop) wrote:
In <jk********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
1. Technically, the discussion is about objects, identifiers that ^^^^^^^^^^^ designate/denote objects (aka variable names in C++), and values.


Nope, the discussion was about "variables".


Then, pray tell, how is the term "variable" defined, WRT to the C
language? Those who were using it were actually talking about named
objects, *technically*. However, except for C++, the term variable
isn't officially defined to mean "named object".
As long as c.l.c is still an imperfect ivory tower (i.e. it still has
connections with the real world) it is highly unrealistic to ignore
popular CS jargon terms like "variable" and "global", simply because the
C standard itself doesn't use them.


It's indeed highly unrealistic to expect everyone to avoid those
terms. However, a quick look in the archives shows that the use of
correct, well-defined terms, instead of sloppy jargon, serves well to
reduce the risk of confusion. What's wrong with object, external
linkage, file scope, etc.pp., after all?


I'm all for using correct terms. What would you call 'a' here:

int main()
{
int a = 1;
return 0;
}
Nov 14 '05 #201
Julie <ju***@nospam.com> wrote:
<much snippage>
I'm all for using correct terms. What would you call 'a' here:

int main()
{
int a = 1;
return 0;
}


Technically correct:
'a' is an identifier designating an object of type int.

Jargon (and in this case I think there's no place for confusion):
'a' is a variable of type int.

That was easy ;-). Now for the next round, you first:
What would you call p and *p, respectively?

int main(void)
{
int a = 1;
int *p = &a;
*p = 2;
return 0;
}

Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #202
Irrwahn Grausewitz wrote:
Julie <ju***@nospam.com> wrote:
<much snippage>
I'm all for using correct terms. What would you call 'a' here:

int main()
{
int a = 1;
return 0;
}

Technically correct:
'a' is an identifier designating an object of type int.

Jargon (and in this case I think there's no place for confusion):
'a' is a variable of type int.

That was easy ;-). Now for the next round, you first:
What would you call p and *p, respectively?

int main(void)
{
int a = 1;
int *p = &a;
*p = 2;
return 0;
}

To help all people involved in this really boring discussion, here are
some definitions of the C++98 standard:
"A variable is introduced by the declaration of an object. The
variable’s name denotes the object."
"The constructs in a C++ program create, destroy, refer to, access, and
manipulate objects. An object is a region of storage. [Note: A function
is not an object, regardless of whether or not it occupies storage in
the way that objects do. ] An object is created by a definition (3.1),
by a new-expression (5.3.4) or by the implementation (12.2) when needed.
The properties of an object are determined when the object is created.
An object can have a name (clause 3). An object has a storage duration
(3.7) which influences its lifetime (3.8). An object has a type (3.9).
The term object type refers to the type with which the object is created.

Some objects are polymorphic (10.3); the implementation generates
information associated with each such object that makes it possible to
determine that object’s type during program execution. For other
objects, the interpretation of the values found therein is determined by
the type of the expressions (clause 5) used to access them.

Objects can contain other objects, called sub-objects. A sub-object
can be a member sub-object (9.2), a base class sub-object
(clause 10), or an array element. An object that is not a sub-object
of any other object is called a complete object.

For every object x, there is some object called the complete object of
x, determined as follows:

— If x is a complete object, then x is the complete object of x.
— Otherwise, the complete object of x is the complete object of the
(unique) object that contains x.

If a complete object, a data member (9.2), or an array element is of
class type, its type is considered the most derived class, to
distinguish it from the class type of any base class sub-object; an
object of a most derived class type is called a most derived object.

Unless it is a bit-field (9.6), a most derived object shall have a
non-zero size and shall occupy one or more bytes of storage. Base class
sub-objects may have zero size. An object of POD4) type (3.9) shall
occupy contiguous bytes of storage.

[Note: C++ provides a variety of built-in types and several ways of
composing new types from existing types (3.9). ]"


Regards,

Ioannis Vranos
Nov 14 '05 #203
Irrwahn Grausewitz wrote:

Julie <ju***@nospam.com> wrote:
<much snippage>
I'm all for using correct terms. What would you call 'a' here:

int main()
{
int a = 1;
return 0;
}


Technically correct:
'a' is an identifier designating an object of type int.

Jargon (and in this case I think there's no place for confusion):
'a' is a variable of type int.

That was easy ;-). Now for the next round, you first:
What would you call p and *p, respectively?

int main(void)
{
int a = 1;
int *p = &a;
*p = 2;
return 0;
}


I call 'p' a "pointer [to an int]" and '*p' "p dereferenced" or "a pointer [to
an int] dereferenced".
Nov 14 '05 #204
Irrwahn Grausewitz <ir*******@freenet.de> writes:
[...]
Then, pray tell, how is the term "variable" defined, WRT to the C
language? Those who were using it were actually talking about named
objects, *technically*. However, except for C++, the term variable
isn't officially defined to mean "named object".


If the C standard itself uses the word "variable" in its common,
somewhat informal sense, then I think we can get away with using it
here in the newsgroup(s).

In addition to a number of examples and footnotes, and ignoring
numerous uses as an adjective, the C99 standard uses the word
"variable" as a noun in normative text in 6.8.5.3p1, 7.6, and F.8.1p1.
(In my opinion, this usage is mildly sloppy, but not sloppy enough to
justify a DR.)

I think we can safely refer to a non-const-qualified object as a
"variable". Whether const-qualified objects are variables is a
question I won't try to answer.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #205
"Dan Pop" <Da*****@cern.ch> wrote in message
news:cc**********@sunnews.cern.ch...
In <nV*******************@newssvr29.news.prodigy.co m> "Mabden" <mabden@sbc_global.net> writes:
Let me help you out be repeating the question and answer for you, Dan.
Q. "What will happen if I compile and run this program??"
A. "You'll get a warning saying main() has no return value."

Do you see a question about standards or committees? No, just "what will
happen". So I showed a specific case of what would happen. Others have
reported their results of what happened.


The OP question was generic! He didn't ask "what will happen if *you*
compile and run this program?", did he? You can't provide an equally
generic answer based on the behaviour of your compiler. Such an answer
must be based on the C language definition.


But, Dan, don't we want to teach these newcomers to code properly? Shouldn't
one point out that a function declared as returning an int, that does not
return an int, may have a flaw?
Ask yourself if my short post (one line) helped to show this general error
that may have deep implications if ignored in large, industrial
applications.
I think my post was consise, and germain, without being overbearing; and
therefore unheard.
Furthermore, the specific behaviour of one compiler or another is usually
considered off topic in this newsgroup, you need a *good* reason for
invoking your compiler's behaviour.


"Brevity is the soul of wit". One can teach without a stick in hand, Dan.
YMMV! ;-) Lighten up, Dan.


Stop behaving like an idiot and I'll lighten up ;-)


Well then, there is no hope... :-P

--
Mabden
Nov 14 '05 #206
Julie <ju***@nospam.com> wrote:
Irrwahn Grausewitz wrote:

Julie <ju***@nospam.com> wrote:
<much snippage>
>I'm all for using correct terms. What would you call 'a' here:
>
>int main()
>{
> int a = 1;
> return 0;
>}


Technically correct:
'a' is an identifier designating an object of type int.

Jargon (and in this case I think there's no place for confusion):
'a' is a variable of type int.

That was easy ;-). Now for the next round, you first:
What would you call p and *p, respectively?

int main(void)
{
int a = 1;
int *p = &a;
*p = 2;
return 0;
}


I call 'p' a "pointer [to an int]" and '*p' "p dereferenced" or "a pointer [to
an int] dereferenced".


So you think the term "variable" is applicable to neither p nor *p?

Here's my proposal:

Technically correct:
'p' is an identifier designating an object of type pointer to int.
'*p' is an expression [dereferencing a pointer value] yielding an
lvalue of type int.

Jargon:
'p' is a pointer variable.
'*p' is a dereferenced address.

However, I'd never call '*p' a variable of type int, though others
mileage may (and obviously does) vary.

BTW: the term "pointer" on itself seems to be ambiguous; it's better
to distinguish "pointer object" or "pointer variable", and "pointer
value" or simply "address".

Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #207
[cross-post to clc++ deliberately stripped]

Keith Thompson <ks***@mib.org> wrote:
Irrwahn Grausewitz <ir*******@freenet.de> writes:
[...]
Then, pray tell, how is the term "variable" defined, WRT to the C
language? Those who were using it were actually talking about named
objects, *technically*. However, except for C++, the term variable
isn't officially defined to mean "named object".
If the C standard itself uses the word "variable" in its common,
somewhat informal sense, then I think we can get away with using it
here in the newsgroup(s).


Ok, but see below.
In addition to a number of examples and footnotes, and ignoring
numerous uses as an adjective, the C99 standard uses the word
"variable" as a noun in normative text in 6.8.5.3p1, 7.6, and F.8.1p1.
(In my opinion, this usage is mildly sloppy, but not sloppy enough to
justify a DR.)
However note that, interestingly, in the standard the term "variable"
is used solely to refer to named objects, but never to refer to
non-atomic expressions yielding modifiable lvalues.
I think we can safely refer to a non-const-qualified object as a
"variable".
I beg to disagree. By that definition *((char *)malloc(1)) and *"abc"
are variables.
Whether const-qualified objects are variables is a
question I won't try to answer.


Indeed; "read-only variable" looks too much like an oxymoron to me.

Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #208
Julie wrote:
Risto Lankinen wrote:
"Julie" <ju***@nospam.com> wrote in message
news:40***************@nospam.com...
Could you please post the relevant code that sets up two variables that


share
the same memory location?


This is a good start:

http://groups.google.fi/groups?selm=...y.DIALix.oz.au

Wha?! Forth? I don't see anything that even remotely describes how to set up
two variables that share the same memory location (_in_C_or_C++_, please).

When posting links, it is _most_ helpful if you first quote the relevant
portion(s), then post the referencing link...

Try again?


OK, I will. A C implementation of a doubly-linked list that uses the same
memory location for both forward and backward pointers follows at the end of
this post.

I suspect you won't be happy with it, but it does store two "conceptual
variables" in one memory location, at least. And it is a moderately
interesting technique, if not (I suspect) hugely useful.

Note that, by it's nature, it isn't portable, relying on being able to convert
a pointer to an unsigned int and back again.

I'm not really a C programmer, so apologies for any hideous blunders and
malapropisms. Additionally, I've left removing nodes as an exercise for the
reader (ahem).

Regards,
Kieran Elby
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

/*
Some platforms will need an unsigned long here.
Some platforms won't be able to use this technique at all.
*/
typedef unsigned int link;

typedef struct {
char *data;
/* This holds the XOR of the addresses of the
next and previous nodes */
link link;
} node;

/*
Add node after nodes n1 and n2.
n2 must be adjacent to n1.
*/
node* add_node(node *n1, node *n2) {

node *n, *n3, *n4;

n = malloc(sizeof(node));
n->data = 0;

if (!n2) {
n3 = 0;
} else {
n3 = (node *) (n2->link ^ (link) n1);
}

n->link = (link) n2 ^ (link) n3;

if (n2) {
n2->link = (link) n1 ^ (link) n;
}

if (n3) {
n4 = (node *) (n3->link ^ (link) n2);
n3->link = (link) n ^ (link) n4;
}

return n;
}

/*
Get node after nodes n1 and n2.
n2 must be adjacent to n1.
*/
node* next_node(node *n1, node *n2) {
if (n1) {
return (node *) (n2->link ^ (link) n1);
} else {
return (node *) n2->link;
}
}

void print_nodes(node *n1, node *n2) {

node *n;

while (1) {
printf(n2->data);
n = next_node(n1, n2);
n1 = n2;
n2 = n;
if (!n) {
break;
}
}
}

int main(void) {

node *nA, *nB, *nC, *nX;

/* Won't work without this */
assert(sizeof(link) >= sizeof(node *));

/* Create list of nodes A, B, C */

nA = add_node(0,0);
nA->data = "A";

nB = add_node(0,nA);
nB->data = "B";

nC = add_node(nA,nB);
nC->data = "C";

/* Add X between B and C */

nX = add_node(nA,nB);
nX->data = "X";

/* Traverse nodes forwards */

printf("Forwards: ");
print_nodes(0, nA);
printf("\n");

/* Traverse nodes backwards */

printf("Backwards: ");
print_nodes(0, nC);
printf("\n");

return 0;
}
Nov 14 '05 #209

"Irrwahn Grausewitz" <ir*******@freenet.de> wrote in message
news:il********************************@4ax.com...
[cross-post to clc++ deliberately stripped]

Keith Thompson <ks***@mib.org> wrote:

Whether const-qualified objects are variables is a
question I won't try to answer.


Indeed; "read-only variable" looks too much like an oxymoron to me.


In the embedded world, there are many non-const variables we
don't have write access too. But they're usually "volatile" because
someone else writes them.
Nov 14 '05 #210
In <of********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote:
In <jk********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
1. Technically, the discussion is about objects, identifiers that ^^^^^^^^^^^ designate/denote objects (aka variable names in C++), and values.


Nope, the discussion was about "variables".


Then, pray tell, how is the term "variable" defined, WRT to the C
language? Those who were using it were actually talking about named
objects, *technically*. However, except for C++, the term variable
isn't officially defined to mean "named object".
As long as c.l.c is still an imperfect ivory tower (i.e. it still has
connections with the real world) it is highly unrealistic to ignore
popular CS jargon terms like "variable" and "global", simply because the
C standard itself doesn't use them.


It's indeed highly unrealistic to expect everyone to avoid those
terms. However, a quick look in the archives shows that the use of
correct, well-defined terms, instead of sloppy jargon, serves well to
reduce the risk of confusion. What's wrong with object, external
linkage, file scope, etc.pp., after all?


Nothing, except that answering a newbie question in a jargon that is
completely unknown to him is not going to *really* help him. Neither is
pointing him to the standard, so that he learns the "proper" terminology.

If you really want to help a newbie, you *must* use the terminology he
understands. It's as simple as that, hence my reference to the perfect
ivory tower.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #211
In <yD*****************@newssvr27.news.prodigy.com> "Mabden" <mabden@sbc_global.net> writes:
"Dan Pop" <Da*****@cern.ch> wrote in message
news:cc**********@sunnews.cern.ch...
In <nV*******************@newssvr29.news.prodigy.co m> "Mabden"<mabden@sbc_global.net> writes:
>Let me help you out be repeating the question and answer for you, Dan.
>Q. "What will happen if I compile and run this program??"
>A. "You'll get a warning saying main() has no return value."
>
>Do you see a question about standards or committees? No, just "what will
>happen". So I showed a specific case of what would happen. Others have
>reported their results of what happened.


The OP question was generic! He didn't ask "what will happen if *you*
compile and run this program?", did he? You can't provide an equally
generic answer based on the behaviour of your compiler. Such an answer
must be based on the C language definition.


But, Dan, don't we want to teach these newcomers to code properly? Shouldn't
one point out that a function declared as returning an int, that does not
return an int, may have a flaw?


Yup, most definitely, but not by making patently false statements.
Ask yourself if my short post (one line) helped to show this general error
that may have deep implications if ignored in large, industrial
applications.
I think my post was consise, and germain, without being overbearing; and
therefore unheard.


Your post was technically incorrect and therefore, unsuitable for
technical newsgroups, period.
Furthermore, the specific behaviour of one compiler or another is usually
considered off topic in this newsgroup, you need a *good* reason for
invoking your compiler's behaviour.


"Brevity is the soul of wit". One can teach without a stick in hand, Dan.


Blatantly false statements are the worst way of teaching. Imagine that
the OP doesn't get any warning, which is quite likely (e.g. gcc doesn't
warn by default). What is he supposed to understand from your post?
Are you helping *or* confusing the OP?

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #212
Irrwahn Grausewitz wrote:

Julie <ju***@nospam.com> wrote:
Irrwahn Grausewitz wrote:

Julie <ju***@nospam.com> wrote:
<much snippage>

>I'm all for using correct terms. What would you call 'a' here:
>
>int main()
>{
> int a = 1;
> return 0;
>}

Technically correct:
'a' is an identifier designating an object of type int.

Jargon (and in this case I think there's no place for confusion):
'a' is a variable of type int.

That was easy ;-). Now for the next round, you first:
What would you call p and *p, respectively?

int main(void)
{
int a = 1;
int *p = &a;
*p = 2;
return 0;
}


I call 'p' a "pointer [to an int]" and '*p' "p dereferenced" or "a pointer [to
an int] dereferenced".


So you think the term "variable" is applicable to neither p nor *p?


I'd call p a variable, but not *p. I'd say that *p might /point/ to a
variable, but that is it.
Nov 14 '05 #213
"Dan Pop" <Da*****@cern.ch> wrote in message
news:cc**********@sunnews.cern.ch...
Are you helping *or* confusing the OP?


<sigh> Yes Dan, you are surely right, as always. I will try to refrain for
posting, as we all should. Only Dan Pop has the right answers. When will we
all learn to shut up and let You speak Your word to enlighten us all. I'm
not worthy, I'm not worthy...

--
Mabden
Nov 14 '05 #214
In article <1j*****************@newssvr25.news.prodigy.com> ,
mabden@sbc_global.net says...
"Dan Pop" <Da*****@cern.ch> wrote in message
news:cc**********@sunnews.cern.ch...
Are you helping *or* confusing the OP?


<sigh> Yes Dan, you are surely right, as always. I will try to refrain for
posting, as we all should. Only Dan Pop has the right answers. When will we
all learn to shut up and let You speak Your word to enlighten us all. I'm
not worthy, I'm not worthy...


At last the grasshopper finally understands Dan.

:-)

Nov 14 '05 #215
Julie <ju***@nospam.com> wrote:
Irrwahn Grausewitz wrote:
Julie <ju***@nospam.com> wrote:
>Irrwahn Grausewitz wrote: <snip> >> What would you call p and *p, respectively?
>>
>> int main(void)
>> {
>> int a = 1;
>> int *p = &a;
>> *p = 2;
>> return 0;
>> }
>
>I call 'p' a "pointer [to an int]" and '*p' "p dereferenced" or "a pointer [to
>an int] dereferenced".
So you think the term "variable" is applicable to neither p nor *p?


I'd call p a variable, but not *p.


I agree with you here.
I'd say that *p might /point/ to a
variable, but that is it.


I beg to differ, I'd rather say that p points to a variable.

Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #216
"Rufus V. Smith" <no****@nospam.com> wrote:
"Irrwahn Grausewitz" <ir*******@freenet.de> wrote in message
news:il********************************@4ax.com.. .
[cross-post to clc++ deliberately stripped]

Keith Thompson <ks***@mib.org> wrote:

>Whether const-qualified objects are variables is a
>question I won't try to answer.


Indeed; "read-only variable" looks too much like an oxymoron to me.


In the embedded world, there are many non-const variables we
don't have write access too. But they're usually "volatile" because
someone else writes them.


Right; I should've written: the term "constant variable" looks like
an oxymoron.

Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #217
Da*****@cern.ch (Dan Pop) wrote:
Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote: <snip>
As long as c.l.c is still an imperfect ivory tower (i.e. it still has
connections with the real world) it is highly unrealistic to ignore
popular CS jargon terms like "variable" and "global", simply because the
C standard itself doesn't use them.
It's indeed highly unrealistic to expect everyone to avoid those
terms. However, a quick look in the archives shows that the use of
correct, well-defined terms, instead of sloppy jargon, serves well to
reduce the risk of confusion. What's wrong with object, external
linkage, file scope, etc.pp., after all?


Nothing, except that answering a newbie question in a jargon that is
completely unknown to him is not going to *really* help him.


Agreed, but it's IMHO likely to confuse newbies, if e.g. someone calls
a dereferenced pointer a variable, as happened up-thread.
Neither is
pointing him to the standard, so that he learns the "proper" terminology.
Definitly; it's much better to explain the "proper" terminology in
context. I consider this to be one (albeit not main) purpose of this
news-group.
If you really want to help a newbie, you *must* use the terminology he
understands. It's as simple as that, hence my reference to the perfect
ivory tower.


Fortunately, c.l.c will never become a perfect ivory tower, or at
the very least as long as I continue to post here... ;-)

Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #218
Julie wrote:

pete wrote:

Julie wrote:
Please describe (in code) a situation where two
variables share the same memory location.
In post
http://groups.google.com/groups?selm...mindspring.com
in the function n_sort, the variable (*node),
has the same address as either (tail) or (head) after this line:

node = GT(head, tail) ? &tail : &head;


Try again.

No *variable* is sharing the same address. Node, head, and tail all have
different addresses, unless you can say that any of the following is true:

&node == &head == &tail

It doesn't matter what node _points_ to, it matters where node _is_.

Under your logic, the following two variables:

int a = 1;
int b = 2;

become the _same_ same variable with the following:

b = 1;

Surely you don't now consider a and b the same _variable_, do you?


No, I don't, and don't call me Shurly.

For
int *pointer = &b;

*pointer has the same address as b.
*pointer is a variable.

Remember, we are talking about _addresses_ of variables,
not the _value_ of variables.


*node is a variable.
In the code example, *node has the same address as either
*tail or *head.

--
pete
Nov 14 '05 #219
In <1j*****************@newssvr25.news.prodigy.com> "Mabden" <mabden@sbc_global.net> writes:
"Dan Pop" <Da*****@cern.ch> wrote in message
news:cc**********@sunnews.cern.ch...
Are you helping *or* confusing the OP?
<sigh> Yes Dan, you are surely right, as always.


I am right when I am right and wrong when I am wrong. I am neither
always right nor always wrong.
I will try to refrain for posting, as we all should.
When not having the correct answer.
Only Dan Pop has the right answers. When will we
all learn to shut up and let You speak Your word to enlighten us all. I'm
not worthy, I'm not worthy...


Cut the crap!

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #220
In <cr********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Julie <ju***@nospam.com> wrote:
Irrwahn Grausewitz wrote:
Julie <ju***@nospam.com> wrote:
>Irrwahn Grausewitz wrote:<snip> >> What would you call p and *p, respectively?
>>
>> int main(void)
>> {
>> int a = 1;
>> int *p = &a;
>> *p = 2;
>> return 0;
>> }
>
>I call 'p' a "pointer [to an int]" and '*p' "p dereferenced" or "a pointer [to
>an int] dereferenced".

So you think the term "variable" is applicable to neither p nor *p?


I'd call p a variable, but not *p.


I agree with you here.


How would you call *p, though? It has the semantics of a variable,
doesn't it?
I'd say that *p might /point/ to a
variable, but that is it.


I beg to differ, I'd rather say that p points to a variable.


That's something too subtle for Julie to understand. She seems to be
blind to the semantic difference between p (that can point to a variable)
and *p (that *is* the variable pointed to by p).

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #221
In <gs********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote:
Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote:<snip>As long as c.l.c is still an imperfect ivory tower (i.e. it still has
connections with the real world) it is highly unrealistic to ignore
popular CS jargon terms like "variable" and "global", simply because the
C standard itself doesn't use them.

It's indeed highly unrealistic to expect everyone to avoid those
terms. However, a quick look in the archives shows that the use of
correct, well-defined terms, instead of sloppy jargon, serves well to
reduce the risk of confusion. What's wrong with object, external
linkage, file scope, etc.pp., after all?


Nothing, except that answering a newbie question in a jargon that is
completely unknown to him is not going to *really* help him.


Agreed, but it's IMHO likely to confuse newbies, if e.g. someone calls
a dereferenced pointer a variable, as happened up-thread.


I disagree. It's perfectly intuitive (unless you happen to be Julie):
p points to a variable and *p is the variable pointed to by p. Why would
a newbie be confused by the simplest thing about pointers in C?
Neither is
pointing him to the standard, so that he learns the "proper" terminology.


Definitly; it's much better to explain the "proper" terminology in
context. I consider this to be one (albeit not main) purpose of this
news-group.


When replying to a newbie question, you must consider the newbie's
priorities. Giving him a full lesson about the "proper" terminology
instead of providing a simple explanation in terms he already understands
is not exactly what I call helpful. There is plenty of time to learn
the "proper" terminology later and most people have nothing to lose by
never learning it. Again, real world vs the ivory tower: I've been
programming for years without the slightest clue about the "proper"
terminology and the code written back then is still working...
If you really want to help a newbie, you *must* use the terminology he
understands. It's as simple as that, hence my reference to the perfect
ivory tower.


Fortunately, c.l.c will never become a perfect ivory tower, or at
the very least as long as I continue to post here... ;-)


Then, why are you arguing on the ivory tower side? ;-)

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #222
pete wrote:

Julie wrote:

pete wrote:

Julie wrote:

> Please describe (in code) a situation where two
> variables share the same memory location.

In post
http://groups.google.com/groups?selm...mindspring.com
*node is a variable.
In the code example, *node has the same address as either
*tail or *head.


I meant:

"In the code example, *node has the same address as either
tail or head."

--
pete
Nov 14 '05 #223
Irrwahn Grausewitz wrote:

Julie <ju***@nospam.com> wrote:
Irrwahn Grausewitz wrote:
Julie <ju***@nospam.com> wrote:
>Irrwahn Grausewitz wrote: <snip> >> What would you call p and *p, respectively?
>>
>> int main(void)
>> {
>> int a = 1;
>> int *p = &a;
>> *p = 2;
>> return 0;
>> }
>
>I call 'p' a "pointer [to an int]" and '*p' "p dereferenced" or "a pointer [to
>an int] dereferenced".

So you think the term "variable" is applicable to neither p nor *p?


I'd call p a variable, but not *p.


I agree with you here.
I'd say that *p might /point/ to a
variable, but that is it.


I beg to differ, I'd rather say that p points to a variable.


In context specific conditions (such as the code above), this is true where p
points to a.

However (and it wasn't clear in my response), generally speaking: an arbitrary
point x *may* point to a variable, but not necessarily.
Nov 14 '05 #224
Dan Pop wrote:

In <cr********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Julie <ju***@nospam.com> wrote:
Irrwahn Grausewitz wrote:
Julie <ju***@nospam.com> wrote:
>Irrwahn Grausewitz wrote:

<snip>
>> What would you call p and *p, respectively?
>>
>> int main(void)
>> {
>> int a = 1;
>> int *p = &a;
>> *p = 2;
>> return 0;
>> }
>
>I call 'p' a "pointer [to an int]" and '*p' "p dereferenced" or "a pointer [to
>an int] dereferenced".

So you think the term "variable" is applicable to neither p nor *p?

I'd call p a variable, but not *p.


I agree with you here.


How would you call *p, though? It has the semantics of a variable,
doesn't it?
I'd say that *p might /point/ to a
variable, but that is it.


I beg to differ, I'd rather say that p points to a variable.


That's something too subtle for Julie to understand. She seems to be
blind to the semantic difference between p (that can point to a variable)
and *p (that *is* the variable pointed to by p).


Dan -- your condescending attitude benefits no one in this newsgroup, and only
selfishly serves you.

I was speaking in general terms, not specifically. In the case of the code
posted, *p does point to a variable a, but only in this specific case. In
general terms, a pointer x *may* point to a variable.

Here are some examples of pointers that do *not* point to variables:

int * x = NULL;

const int b = 123;
const int * w = &b;

int * r = &printer_port_out;
Nov 14 '05 #225

"Julie" <ju***@nospam.com> wrote in message
news:40***************@nospam.com...
Dan Pop wrote:

In <cr********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Julie <ju***@nospam.com> wrote:

That's something too subtle for Julie to understand. She seems to be blind to the semantic difference between p (that can point to a variable) and *p (that *is* the variable pointed to by p).
Dan -- your condescending attitude benefits no one in this

newsgroup, and only selfishly serves you.


It doesn't serve him very well. ;-)

Jonathan
Nov 14 '05 #226
Dan Pop wrote:
That's something too subtle for Julie to understand. She seems to be
blind to the semantic difference between p (that can point to a variable)
and *p (that *is* the variable pointed to by p).

Well, you and Julie actually use the term variable in the place of the
term object.
As the C++ standard says:

"A variable is introduced by the declaration of an object. The
variable’s name denotes the object."

"An object is a region of storage. [Note: A function is not an object,
regardless of whether or not it occupies storage in the way that objects
do. ] An object is created by a definition (3.1), by a new-expression
(5.3.4) or by the implementation (12.2) when needed."
So in terminology, a variable can only denote one object, which is
always different from another object.
The original question becomes "what if we pass the same object to the
swap function?".
If you do not use the correct terminology, you will never reach a
conclusion, since both of you use your own terminologies.
----

A pointer is a variable that denotes an object (which stores addresses).

A dereferenced pointer is not a variable (since it is not introduced by
the declaration of an object), but represents an object.
As I said, the original question becomes: "what if we pass the same
object to the swap function?".

It would be nice if you tried to communicate on this basis.


Regards,

Ioannis Vranos,

Language Lawyer :-)
Nov 14 '05 #227
Julie wrote:

Dan Pop wrote:

In <cr********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Julie <ju***@nospam.com> wrote:
>Irrwahn Grausewitz wrote:
>> Julie <ju***@nospam.com> wrote:
>> >Irrwahn Grausewitz wrote:
<snip>
>> >> What would you call p and *p, respectively?
>> >>
>> >> int main(void)
>> >> {
>> >> int a = 1;
>> >> int *p = &a;
>> >> *p = 2;
>> >> return 0;
>> >> }
>> >I'd call p a variable, but not *p.

I agree with you here.


How would you call *p, though? It has the semantics of a variable,
doesn't it?
>I'd say that *p might /point/ to a
>variable, but that is it.

I beg to differ, I'd rather say that p points to a variable.


That's something too subtle for Julie to understand.
She seems to be
blind to the semantic difference between p
(that can point to a variable)
and *p (that *is* the variable pointed to by p).


Dan -- your condescending attitude
benefits no one in this newsgroup, and only
selfishly serves you.

I was speaking in general terms, not specifically.
In the case of the code posted,
*p does point to a variable a,


No it doesn't.
*p is an object of type int. It doesn't point anywhere.

--
pete
Nov 14 '05 #228
Da*****@cern.ch (Dan Pop) wrote:
In <gs********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
<snip>
Agreed, but it's IMHO likely to confuse newbies, if e.g. someone calls
a dereferenced pointer a variable, as happened up-thread.


I disagree. It's perfectly intuitive (unless you happen to be Julie):
p points to a variable and *p is the variable pointed to by p. Why would
a newbie be confused by the simplest thing about pointers in C?


IMO we should agree to disagree: *p is not a proper identifier and it
can't be initialized on declaration, thus it's not a variable. *p is
the contents of the memory location p points to, converted to the type
p is a pointer to.

<snip>
Definitly; it's much better to explain the "proper" terminology in
context. I consider this to be one (albeit not main) purpose of this
news-group.


When replying to a newbie question, you must consider the newbie's
priorities. Giving him a full lesson about the "proper" terminology
instead of providing a simple explanation in terms he already understands
is not exactly what I call helpful.


Is your world really black and white only? There's not a great void
between a simple explanation and an exhaustive lecture in applied
Standardese. A comprehensible explanation, enriched with some
additional remarks about terminology (or other theoretical concepts,
for that matter) is what I'd call not only helpful, but educative,
too.
There is plenty of time to learn
the "proper" terminology later and most people have nothing to lose by
never learning it. Again, real world vs the ivory tower: I've been
programming for years without the slightest clue about the "proper"
terminology and the code written back then is still working...


You're not the only one. But, again, what's wrong with learning
something correct every once in a while, even if it's not highly
important for the practical solution of the problem at hand?

<snip>
Fortunately, c.l.c will never become a perfect ivory tower, or at
the very least as long as I continue to post here... ;-)


Then, why are you arguing on the ivory tower side? ;-)


Since I'm not, the only correct answer to this question is: Mu. ;-)

Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #229
Da*****@cern.ch (Dan Pop) wrote:
In <cr********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Julie <ju***@nospam.com> wrote:
Irrwahn Grausewitz wrote:
Julie <ju***@nospam.com> wrote:
>Irrwahn Grausewitz wrote:

<snip>
>> What would you call p and *p, respectively?
>>
>> int main(void)
>> {
>> int a = 1;
>> int *p = &a;
>> *p = 2;
>> return 0;
>> }
>
>I call 'p' a "pointer [to an int]" and '*p' "p dereferenced" or "a pointer [to
>an int] dereferenced".

So you think the term "variable" is applicable to neither p nor *p?

I'd call p a variable, but not *p.


I agree with you here.


How would you call *p, though? It has the semantics of a variable,
doesn't it?


But only to some degree, and only in this special case, where p
happens to point to an object created by declaration of a variable,
that coincidentally has the same type p is a pointer to. See also
my reply in the other (non-crossposted) sub-thread, as well as
Ioannis' reply <cc***********@ulysses.noc.ntua.gr>, with which I
wholeheartedly agree.

<snip>
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #230
In <9e********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote:
In <gs********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
<snip>
Agreed, but it's IMHO likely to confuse newbies, if e.g. someone calls
a dereferenced pointer a variable, as happened up-thread.


I disagree. It's perfectly intuitive (unless you happen to be Julie):
p points to a variable and *p is the variable pointed to by p. Why would
a newbie be confused by the simplest thing about pointers in C?


IMO we should agree to disagree: *p is not a proper identifier and it


Who sez it should be?
can't be initialized on declaration,
If it's not a proper identifier, you cannot declare it. But this doesn't
make it any less variable.
thus it's not a variable.
By *your* narrow minded definition of variable.
*p is
the contents of the memory location p points to, converted to the type
p is a pointer to.
Which is good enough to be called variable, unless the object in question
was declared as const.

BTW, a variable doesn't even need to have a name or to be declared.

int *p = malloc(sizeof *p);

creates an unnamed variable. You can access it with *p, just as you can
access a named variable whose address is stored in p.
<snip>
Definitly; it's much better to explain the "proper" terminology in
context. I consider this to be one (albeit not main) purpose of this
news-group.
When replying to a newbie question, you must consider the newbie's
priorities. Giving him a full lesson about the "proper" terminology
instead of providing a simple explanation in terms he already understands
is not exactly what I call helpful.


Is your world really black and white only?


Non sequitur. See below.
There's not a great void
between a simple explanation and an exhaustive lecture in applied
Standardese. A comprehensible explanation, enriched with some
additional remarks about terminology (or other theoretical concepts,
for that matter) is what I'd call not only helpful, but educative,
too.


Not if the poster has a completely different set of priorities, i.e. he is
already struggling to understand the concepts from his C book, using the
author's terminology and the last thing he needs is more new concepts and
definitions. Maybe you have forgotten those days, but I haven't (heck,
it's a mere 16 years ago).
There is plenty of time to learn
the "proper" terminology later and most people have nothing to lose by
never learning it. Again, real world vs the ivory tower: I've been
programming for years without the slightest clue about the "proper"
terminology and the code written back then is still working...


You're not the only one. But, again, what's wrong with learning
something correct every once in a while, even if it's not highly
important for the practical solution of the problem at hand?


See above. The newbie is already learning a lot of things in a short
time, so your "once in a while" is strongly misplaced. When the OP is not
a newbie (it's quite easy to tell the difference, even if he doesn't
mention), correcting improper terminology is a must. As I said, it's a
matter of getting the priorities right. So where does my black and white
world comes from?

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #231
Da*****@cern.ch (Dan Pop) wrote:
In <9e********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
<snippage>
[...] *p is not a proper identifier and it
can't be initialized on declaration,
thus it's not a variable.


By *your* narrow minded definition of variable.


I'd call it sensible. <OT> And, BTW, it matches the definition in the
C++ standard, a language distinct from C, but closely related. </OT>

<snip>BTW, a variable doesn't even need to have a name or to be declared.

int *p = malloc(sizeof *p);

creates an unnamed variable. You can access it with *p, just as you can
access a named variable whose address is stored in p.
By your logic, given char *p = "abc"; *p constitutes a variable of
type char.

<snip>Not if the poster has a completely different set of priorities, i.e. he is
already struggling to understand the concepts from his C book, using the
author's terminology and the last thing he needs is more new concepts and
definitions. Maybe you have forgotten those days, but I haven't (heck,
it's a mere 16 years ago).
I certainly didn't (coincidentally, it's only about 16 years ago for
me, too), but I was always grateful when my local C guru corrected my
flawed mental image of basic concepts and terminology, as soon as
possible. YMMV.

<snip> When the OP is not
a newbie (it's quite easy to tell the difference, even if he doesn't
mention), correcting improper terminology is a must. As I said, it's a
matter of getting the priorities right.
I cannot see the benefit of first teaching sloppiness to newbies and
then give them a hard time to get it correct later. Again, YMMV.
So where does my black and white
world comes from?


Since you're the only one able to provide a sensible answer to this
question, how am I supposed to know?

Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #232
In <5n********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote:
In <9e********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
<snippage>
[...] *p is not a proper identifier and it
can't be initialized on declaration,
thus it's not a variable.


By *your* narrow minded definition of variable.


I'd call it sensible. <OT> And, BTW, it matches the definition in the
C++ standard, a language distinct from C, but closely related. </OT>


If you believe that standards are the right source of definitions for
terms used outside of those standards context, I invite you to read
the C standard definition of the term "byte". Use it in a non-C
context and people will laugh at you.

The definition from the C++ standard is predating languages supporting
pointers. In good old FORTRAN, you needed a name to access a variable.
<snip>
BTW, a variable doesn't even need to have a name or to be declared.

int *p = malloc(sizeof *p);

creates an unnamed variable. You can access it with *p, just as you can
access a named variable whose address is stored in p.
By your logic, given char *p = "abc"; *p constitutes a variable of
type char.


Nope. p doesn't point to a modifiable object, does it? So, how can you
invoke *my* logic?

Translated in the C lingo, a variable is a modifiable object whose
address is known. So, memory leaks, const objects and string literals
don't count.
<snip>
Not if the poster has a completely different set of priorities, i.e. he is
already struggling to understand the concepts from his C book, using the
author's terminology and the last thing he needs is more new concepts and
definitions. Maybe you have forgotten those days, but I haven't (heck,
it's a mere 16 years ago).
I certainly didn't (coincidentally, it's only about 16 years ago for
me, too), but I was always grateful when my local C guru corrected my
flawed mental image of basic concepts and terminology, as soon as
possible. YMMV.


No need to muddle the issue: we're NOT talking here about flawed mental
images of basic concepts, the discussion is strictly limited to
terminology issues. No one was arguing about preserving the newbies'
misconceptions about the language!

And my mileage did vary, because I was self taught and was the only one
using C around. So, I had to act as my own guru, using the online help
of VAX C as my one and only reference documentation (in addition to my
handwritten copy of Appendix A of K&R1).
<snip>
When the OP is not
a newbie (it's quite easy to tell the difference, even if he doesn't
mention), correcting improper terminology is a must. As I said, it's a
matter of getting the priorities right.


I cannot see the benefit of first teaching sloppiness to newbies and
then give them a hard time to get it correct later. Again, YMMV.


Is K&R2 teaching sloppiness to newbies, by not using the C standard
terminology? The term "variable" is intensively used by Kernighan, in the
tutorial part. And, horror of horrors, he's also talking about operator
precedence and associativity, which is sheer heresy in the eyes of the
anal c.l.c regular. OTOH, good luck trying to find any mention of
undefined behaviour...

Although you may be unable to get it, the standard terminology is not
needed to teach C programming correctly. Even the C standard is
occasionally using the term "variable":

10 EXAMPLE 2 In executing the fragment

char c1, c2;
/* ... */
c1 = c1 + c2;

the ``integer promotions'' require that the abstract machine
promote the value of each variable to int size and then add the
two ints and truncate the sum.
....
41) Thus, an automatic variable can be initialized to a trap
representation without causing undefined behavior, but the
value of the variable cannot be used until a proper value
is stored in it.
....
equal. Therefore, for full portability, the variable c should
be declared as int.
....
If clause-1
is a declaration, the scope of any variables it declares is the
remainder of the declaration and the entire loop, including the
other two expressions;
....
133) Thus, clause-1 specifies initialization for the loop,
possibly declaring one or more variables for use in the
loop;
....
164) For a variable z of complex type, z == creal(z) + cimag(z)*I.
....
A floating-point status flag is a
system variable whose value is set (but never cleared) when a
floating-point exception is raised, which occurs as a side effect
of exceptional floating-point arithmetic to provide auxiliary
information. A floating-point control mode is a system variable
whose value may be set by the user to affect the subsequent
behavior of floating-point arithmetic.
So where does my black and white world comes from?


Since you're the only one able to provide a sensible answer to this
question, how am I supposed to know?


You made the accusation, you have to support it! Or apologise, if unable
to support it.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #233
Da*****@cern.ch (Dan Pop) wrote:
In <5n********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote:
<much snippage>
Although you may be unable to get it, the standard terminology is not
needed to teach C programming correctly. Even the C standard is
occasionally using the term "variable":
[Occurrences of the term "variable" in the standard snipped.]

I did the search myself some time ago, and, as I already mentioned
elsethread, the term "variable" in the standard is used solely to
describe named objects. Thanks for making my point.
So where does my black and white world comes from?


Since you're the only one able to provide a sensible answer to this
question, how am I supposed to know?


You made the accusation, you have to support it!


How is the question "Is your world really black and white only?" to
be taken as accusation? Take your own advice and learn to read for
comprehension, Dan!
Or apologise, if unable to support it.


No accusation - no apology. Oh, and on a more general note: I suggest
you cease to request politeness from others, up until your own social
skills conform to at least stone-age standards; thank you.

Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #234
In <5b********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote:
In <5n********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote:
<much snippage>
Although you may be unable to get it, the standard terminology is not
needed to teach C programming correctly. Even the C standard is
occasionally using the term "variable":
[Occurrences of the term "variable" in the standard snipped.]

I did the search myself some time ago, and, as I already mentioned
elsethread, the term "variable" in the standard is used solely to
describe named objects. Thanks for making my point.


How many examples in the standard deal with unnamed objects? Are you sure
your point has any validity at all?
So where does my black and white world comes from?

Since you're the only one able to provide a sensible answer to this
question, how am I supposed to know?


You made the accusation, you have to support it!


How is the question "Is your world really black and white only?" to
be taken as accusation?


I've never seen it used it as a compliment, so please enlighten me.
Take your own advice and learn to read for comprehension, Dan!


I do. Do you?
Or apologise, if unable to support it.


No accusation - no apology. Oh, and on a more general note: I suggest
you cease to request politeness from others, up until your own social
skills conform to at least stone-age standards; thank you.


Whenever I make an accusation, I'm ready to support it rather than
cowardly pretending that it wasn't an accusation in the first place.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #235
Irrwahn Grausewitz <ir*******@freenet.de> writes:
[...]
[Occurrences of the term "variable" in the standard snipped.]

I did the search myself some time ago, and, as I already mentioned
elsethread, the term "variable" in the standard is used solely to
describe named objects. Thanks for making my point.


There are few enough uses of the term "variable" (as a noun) in the
standard that I don't think we can draw any conclusions about the
precise definition. IMHO, there's not much of a point to be made one
way or the other.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #236
Da*****@cern.ch (Dan Pop) wrote:
In <5b********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote:
In <5n********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote:
<much snippage>
So where does my black and white world comes from?

Since you're the only one able to provide a sensible answer to this
question, how am I supposed to know?

You made the accusation, you have to support it!
How is the question "Is your world really black and white only?" to
be taken as accusation?


I've never seen it used it as a compliment, so please enlighten me.


If you actually think that every assertion or question that is not a
compliment automatically constitutes an accusation, you know the
reason why I felt compelled to ask the question (sic!) in the first
place. And you answered it affirmative in the same sentence. Nice
job.
Take your own advice and learn to read for comprehension, Dan!


I do.


Obviously not.
Do you?


I do my very best.
No accusation - no apology. Oh, and on a more general note: I suggest
you cease to request politeness from others, up until your own social
skills conform to at least stone-age standards; thank you.


Whenever I make an accusation, I'm ready to support it rather than
cowardly pretending that it wasn't an accusation in the first place.


No place for cowardice, since it wasn't an accusation, despite your
obvious lack of ability to differentiate in nuances, rather than
coercing each and every thing in some kind of crude binary system.

However, you showed enough evidence that your world in fact *is* black
and white only. This evidence is to be found above, as well as in
literally thousands of abusenet messages you posted. You know how to
open your out-box, or go ogle, don't you?

If you want to continue this discussion, feel free to send me a
private email.

Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #237
On Mon, 12 Jul 2004 18:33:25 +0200, in comp.lang.c , Irrwahn Grausewitz
<ir*******@freenet.de> wrote:
Da*****@cern.ch (Dan Pop) wrote:
Whenever I make an accusation, I'm ready to support it rather than

Yeah? Like when Dan accused just about everyone else of being an idiot, yet
refused to produce medical evidence to that effect? :-)

Get real.
No place for cowardice, since it wasn't an accusation, despite your
obvious lack of ability to differentiate in nuances, rather than
coercing each and every thing in some kind of crude binary system.


Irrwahn, you're shouting down a well.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #238
Mark McIntyre <ma**********@spamcop.net> wrote:
On Mon, 12 Jul 2004 18:33:25 +0200, in comp.lang.c , Irrwahn Grausewitz
<ir*******@freenet.de> wrote:
Da*****@cern.ch (Dan Pop) wrote:
Whenever I make an accusation, I'm ready to support it rather than


Yeah? Like when Dan accused just about everyone else of being an idiot, yet
refused to produce medical evidence to that effect? :-)

Get real.
No place for cowardice, since it wasn't an accusation, despite your
obvious lack of ability to differentiate in nuances, rather than
coercing each and every thing in some kind of crude binary system.


Irrwahn, you're shouting down a well.


Yup, I know, nice ECHO... echo... e.o... o... o... ;-)

Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #239
In <i4********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote:
In <5b********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote:
In <5n********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
>Da*****@cern.ch (Dan Pop) wrote:
<much snippage>
So where does my black and white world comes from?
>
>Since you're the only one able to provide a sensible answer to this
>question, how am I supposed to know?

You made the accusation, you have to support it!

How is the question "Is your world really black and white only?" to
be taken as accusation?
I've never seen it used it as a compliment, so please enlighten me.


If you actually think that every assertion or question that is not a
compliment automatically constitutes an accusation, you know the
reason why I felt compelled to ask the question (sic!) in the first
place. And you answered it affirmative in the same sentence. Nice
job.


You missed the irony behind my statement, confirming the cliche about
the Germans' sense of humour (or lack thereof).
Take your own advice and learn to read for comprehension, Dan!


I do.


Obviously not.
Do you?


I do my very best.


Which is no guarantee of success.
No accusation - no apology. Oh, and on a more general note: I suggest
you cease to request politeness from others, up until your own social
skills conform to at least stone-age standards; thank you.


Whenever I make an accusation, I'm ready to support it rather than
cowardly pretending that it wasn't an accusation in the first place.


No place for cowardice, since it wasn't an accusation, despite your
obvious lack of ability to differentiate in nuances, rather than
coercing each and every thing in some kind of crude binary system.


On the contrary, I'm quite good at differentiating nuances, therefore
I didn't miss the pejorative one behind your "neutral" question.
If you want to continue this discussion, feel free to send me a
private email.


Why should I bother? I have nothing to hide from anyone...

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #240
In <vf********************************@4ax.com> Mark McIntyre <ma**********@spamcop.net> writes:
On Mon, 12 Jul 2004 18:33:25 +0200, in comp.lang.c , Irrwahn Grausewitz
<ir*******@freenet.de> wrote:
Da*****@cern.ch (Dan Pop) wrote:
Whenever I make an accusation, I'm ready to support it rather than

Yeah? Like when Dan accused just about everyone else of being an idiot,


Accusing you of being an idiot is not exactly the same as accusing
"just about everyone else" of being an idiot.
yet refused to produce medical evidence to that effect? :-)


You produced yourself more than enough factual evidence. Thanks to
Google, it's here to stay ;-)

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #241
Da*****@cern.ch (Dan Pop) wrote:
In <i4********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote:
In <5b********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes: <much snippage>Take your own advice and learn to read for comprehension, Dan!

I do.


Obviously not.
Do you?


I do my very best.


Which is no guarantee of success.


Deliberately acting like the idiot you consider others to be won't
help you here. There is not much of a guarantee for anything in the
real world.
No place for cowardice, since it wasn't an accusation, despite your
obvious lack of ability to differentiate in nuances, rather than
coercing each and every thing in some kind of crude binary system.


On the contrary, I'm quite good at differentiating nuances, therefore
I didn't miss the pejorative one behind your "neutral" question.


Thanks, Dan, you presented just another evidence supporting my theory.
And BTW, mimicking paranoid behaviour doesn't help much, too.
If you want to continue this discussion, feel free to send me a
private email.


Why should I bother? I have nothing to hide from anyone...


C'mon Dan, pretending you're an idiot two times in a single message is
far too much. Get real! My suggestion had nothing to do with hiding
something from someone, but everything with trying to move this OT
private discussion off the group, for the benefit of other readers.
You chose to ignore, so I choose to drop out.

Bye.
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #242
In <gh********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
Da*****@cern.ch (Dan Pop) wrote:

Why should I bother? I have nothing to hide from anyone...


C'mon Dan, pretending you're an idiot two times in a single message is
far too much. Get real! My suggestion had nothing to do with hiding
something from someone, but everything with trying to move this OT
private discussion off the group, for the benefit of other readers.


Bogus argument. Those not interested have killfiled the thread long ago.
Neither you nor I have the slightest clue about who might be still
following this discussion and with what degree of interest.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #243
> Please describe (in code) a situation where two variables share the same memory
location.

Dan you need to try stuff for yourself

#include <stdio.h>

int main(void){
int x=10, *p;
p=&x;
printf("%p, %p\n",(void *)p,(void *)&x);
return 0;
}
Nov 14 '05 #244
"Michael" <mi************@excite.com> wrote in message
news:20**************************@posting.google.c om...
Please describe (in code) a situation where two variables share the same memory location.

Dan you need to try stuff for yourself


Oohhhh.. you're arguing with Dan....

Duck everybody!
Nov 14 '05 #245
Mabden wrote:
"Michael" <mi************@excite.com> wrote in message
news:20**************************@posting.google.c om...
Please describe (in code) a situation where two variables share the same
memory
location.


Dan you need to try stuff for yourself

Oohhhh.. you're arguing with Dan....

Duck everybody!


Eheheh (laughing behind a wall).
Nov 14 '05 #246
Michael wrote:
Please describe (in code) a situation where two variables share the same memory
location.

Dan you need to try stuff for yourself

#include <stdio.h>

int main(void){
int x=10, *p;
p=&x;
printf("%p, %p\n",(void *)p,(void *)&x);
return 0;
}


You need to think a little harder:

You have two variables: x and p. Are you saying that &x == &p? I sure hope
not.

Try again.
Nov 14 '05 #247
Julie <ju***@nospam.com> writes:
Michael wrote:
Please describe (in code) a situation where two variables share
the same memory location.

Dan you need to try stuff for yourself

#include <stdio.h>

int main(void){
int x=10, *p;
p=&x;
printf("%p, %p\n",(void *)p,(void *)&x);
return 0;
}


You need to think a little harder:

You have two variables: x and p. Are you saying that &x == &p? I sure hope
not.

Try again.


No, of course nobody is saying htat &x == &p.

x and p are undeniably variables. The question is whether *p is also
a variable. If it is, the above program demonstrates a situation
where two variables share the same memory location; if it isn't, it
doesn't.

*p is certainly an object. The question of whether it's also a
"variable" is, in my opinion, a profoundly uninteresting one. The C
standard doesn't define "variable" as a technical term. It uses it
(informally) in a few places. It happens that it uses it only to refer
to declared objects, but we can't really infer anything from that.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #248
Keith Thompson wrote:

Julie <ju***@nospam.com> writes:
Michael wrote:
> Please describe (in code) a situation where two variables share
> the same memory location.
>
Dan you need to try stuff for yourself

#include <stdio.h>

int main(void){
int x=10, *p;
p=&x;
printf("%p, %p\n",(void *)p,(void *)&x);
return 0;
}


You need to think a little harder:

You have two variables: x and p. Are you saying that &x == &p? I sure hope
not.

Try again.


No, of course nobody is saying htat &x == &p.

x and p are undeniably variables. The question is whether *p is also
a variable. If it is, the above program demonstrates a situation
where two variables share the same memory location; if it isn't, it
doesn't.

*p is certainly an object. The question of whether it's also a
"variable" is, in my opinion, a profoundly uninteresting one. The C
standard doesn't define "variable" as a technical term. It uses it
(informally) in a few places. It happens that it uses it only to refer
to declared objects, but we can't really infer anything from that.


*p _may_ be an object. Consider the following:

int *p = NULL;

*p is definitely not an object in this case.

Yes, profoundly uninteresting, but somewhat worthy of senseless never-ending
blather, of which I have been a major (unapologetic) contributor.

Since we are in comp.lang.c* newsgroups, the discussions are not strictly
limited to what the standard does/doesn't define -- such restricted topics are
discussed in comp.std.c*.

Using unions it is possible to declare a variable that shares the same
address. Dereferenced pointers (or references in C++) to a variable are at
most an alias to a variable, but not a variable in terms that I consider
well-defined. Others may (and obviously do, hopefully an informed view)
consider the term 'variable' differently.
Nov 14 '05 #249
Julie <ju***@nospam.com> writes:
[...]
*p _may_ be an object. Consider the following:

int *p = NULL;

*p is definitely not an object in this case.
Right, but in the example we've been talking about, p has been
assigned the value &x (where x is a declared int object).
Yes, profoundly uninteresting, but somewhat worthy of senseless never-ending
blather, of which I have been a major (unapologetic) contributor.
As have I from time to time.
Since we are in comp.lang.c* newsgroups, the discussions are not
strictly limited to what the standard does/doesn't define -- such
restricted topics are discussed in comp.std.c*.


Actually, comp.lang.c tends to be about the language as defined by the
standard, whereas comp.std.c is about the standard itself. (I just
noticed that this is cross-posted to comp.lang.c++, which is almost
never a good idea.)

[...]

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #250

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

270
by: Jatinder | last post by:
I found these questions on a web site and wish to share with all of u out there,Can SomeOne Solve these Porgramming puzzles. Programming Puzzles Some companies certainly ask for these...
12
by: G. | last post by:
Hi all, During my degree, BEng (Hons) Electronics and Communications Engineering, we did C programming every year, but I never kept it up, as I had no interest and didn't see the point. But now...
11
by: John Salerno | last post by:
Similar to the Python Challenge, does anyone know of any other websites or books that have programming puzzles to solve? I found a book called "Puzzles for Hackers", but it seems like it might be a...
1
by: xavier vazquez | last post by:
I have a problem with a program that does not working properly...when the program run is suppose to generate a cross word puzzle , when the outcome show the letter of the words overlap one intop of...
0
by: xavier vazquez | last post by:
have a problem with a program that does not working properly...when the program run is suppose to generate a cross word puzzle , when the outcome show the letter of the words overlap one intop of the...
44
by: Jon Harrop | last post by:
Microsoft Research are developing a functional programming language called F# for .NET and I've been playing with it recently. I've uploaded some demos here: ...
5
by: ashish0799 | last post by:
HI I M ASHISH I WANT ALGORYTHMUS OF THIS PROBLEM Jigsaw puzzles. You would have solved many in your childhood and many people still like it in their old ages also. Now what you have got to do...
3
by: oncue01 | last post by:
Word Puzzle Task You are going to search M words in an N × N puzzle. The words may have been placed in one of the four directions as from (i) left to right (E), (ii) right to left (W), (iii) up...
4
by: honey777 | last post by:
Problem: 15 Puzzle This is a common puzzle with a 4x4 playing space with 15 tiles, numbered 1 through 15. One "spot" is always left blank. Here is an example of the puzzle: The goal is to...
13
by: btkuhn | last post by:
Hi guys, I'm learning Python by teaching myself, and after going through several tutorials I feel like I've learned the basics. Since I'm not taking a class or anything, I've been doing...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.