473,386 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how the following two code parts same

how the following two code parts same:

#include <stdio.h>

void main ()
{

char i = NULL;

char &q = i;
^^^^

printf ( "%d", i);

printf ("%d", q);
}

O/p.................. 0 0

#include <stdio.h>

void main ()
{

char i = NULL;

char q = i;
^^

printf ( "%d", i);

printf ("%d", q);
}
O/p ................ 0 0
Dec 7 '07 #1
10 1295
On Dec 7, 1:00 pm, saipathak...@gmail.com wrote:
how the following two code parts same:

#include <stdio.h>

void main ()
{

char i = NULL;

char &q = i;
^^^^

printf ( "%d", i);

printf ("%d", q);

}

O/p.................. 0 0

#include <stdio.h>

void main ()
{

char i = NULL;

char q = i;
^^

printf ( "%d", i);

printf ("%d", q);

}

O/p ................ 0 0
They are the same except for the lines
char &q = i;
and
char q = i;
--
Fred
Dec 7 '07 #2
On Dec 8, 2:03 am, fred.l.kleinschm...@boeing.com wrote:
On Dec 7, 1:00 pm, saipathak...@gmail.com wrote:
how the following two code parts same:
#include <stdio.h>
void main ()
{
char i = NULL;
char &q = i;
^^^^
printf ( "%d", i);
printf ("%d", q);
}
O/p.................. 0 0
#include <stdio.h>
void main ()
{
char i = NULL;
char q = i;
^^
printf ( "%d", i);
printf ("%d", q);
}
O/p ................ 0 0

They are the same except for the lines
char &q = i;
and
char q = i;

--
Fred
i am asking how both code is showing same output.
Dec 7 '07 #3
sa**********@gmail.com wrote:
how the following two code parts same:

#include <stdio.h>

void main ()
Nope. In a hosted environment, main() returns int by definition. You really mean
int main(void)
here
{

char i = NULL;
You should see a diagnostic indicating that you are converting a pointer to an
integer (type) without a cast. Having said that, i should now be initialized
to zero.
>
char &q = i;
Syntax error. Your program should not compile.
>
printf ( "%d", i);

printf ("%d", q);
}

O/p.................. 0 0
I don't believe you.
>
#include <stdio.h>

void main ()
Again,
int main(void)
{

char i = NULL;
You should see a diagnostic indicating that you are converting a pointer to an
integer (type) without a cast. Having said that, i should now be initialized
to zero.
char q = i;
q is initialized to the contents of i. Since i is initialized to zero and not
changed before this statement, q should now also be set to zero.
>
printf ( "%d", i);

printf ("%d", q);
}
O/p ................ 0 0
OK

So, what's your problem?

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------

Dec 7 '07 #4
On Dec 8, 2:13 am, Lew Pitcher <lpitc...@teksavvy.comwrote:
saipathak...@gmail.com wrote:
how the following two code parts same:
#include <stdio.h>
void main ()

Nope. In a hosted environment, main() returns int by definition. You really mean
int main(void)
here
{
char i = NULL;

You should see a diagnostic indicating that you are converting a pointer to an
integer (type) without a cast. Having said that, i should now be initialized
to zero.
char &q = i;

Syntax error. Your program should not compile.
printf ( "%d", i);
printf ("%d", q);
}
O/p.................. 0 0

I don't believe you.
#include <stdio.h>
void main ()

Again,
int main(void)
{
char i = NULL;

You should see a diagnostic indicating that you are converting a pointer to an
integer (type) without a cast. Having said that, i should now be initialized
to zero.
char q = i;

q is initialized to the contents of i. Since i is initialized to zero and not
changed before this statement, q should now also be set to zero.
printf ( "%d", i);
printf ("%d", q);
}
O/p ................ 0 0

OK

So, what's your problem?

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
i compiled in the vc++ .. o/p is same .. is it true with the C++
Dec 7 '07 #5
Lew Pitcher wrote:

char i = NULL;

You should see a diagnostic indicating that you are converting a
pointer to an integer (type) without a cast.
You mean you might see a diagnostic. There's an excellent chance that
NULL is not a pointer type at all.


Brian
Dec 7 '07 #6
sa**********@gmail.com wrote:

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User
Please trim quotes to the minimum necessary for context. Especially
trim the signatures, the parts after -- (I left part in above as an
example).
i compiled in the vc++ .. o/p is same .. is it true with the C++
VC++ can compile C programs. The first code you showed was NOT a C
program, as this:

char &q = i;

Is not a valid C construct. That looks a lot like a reference in C++.
You should probably be posting in comp.lang.c++.

Brian
Dec 7 '07 #7
Default User wrote:
sa**********@gmail.com wrote:
....
i compiled in the vc++ .. o/p is same .. is it true with the C++

VC++ can compile C programs. The first code you showed was NOT a C
program, as this:

char &q = i;

Is not a valid C construct. That looks a lot like a reference in C++.
You should probably be posting in comp.lang.c++.
When you do post to comp.lang.c++, they will tell you that the results
you got are precisely the results you should have expected to get
(ignoring the defective declarations of main()). Save them some time,
and in your first message to that newsgroup, try to explain why it is
that you are surprised by these results. Then they will be able to
explain to you what it is that you're misunderstanding; because you
are misunderstanding something.
Dec 7 '07 #8
Keith Thompson wrote:
sa**********@gmail.com writes:
....
#include <stdio.h>
void main ()
{
char i = NULL;
char &q = i;
^^^^
printf ( "%d", i);
printf ("%d", q);
}

The above is not C. It appears to be C++. Consulting your C++
textbook or the C++ FAQ for information about "references" should
answer your question. Failing that, try comp.lang.c++.
#include <stdio.h>
void main ()

Wrong. Make this "int main(void)" (or "int main()" if you mean to
write C++).
{
char i = NULL;

NULL is a null *pointer* constant. Assigning it to a char object
might happen to work, but it makes no sense. You probably mean
Given that it is C++ code, it will work. In C++, NULL has to have a
value of 0; it cannot have a pointer type.
Dec 7 '07 #9
ja*********@verizon.net writes:
Keith Thompson wrote:
>sa**********@gmail.com writes:
[...]
{
char i = NULL;

NULL is a null *pointer* constant. Assigning it to a char object
might happen to work, but it makes no sense. You probably mean

Given that it is C++ code, it will work. In C++, NULL has to have a
value of 0; it cannot have a pointer type.
True, but using NULL for anything other than a pointer value is poor
style in any case.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 8 '07 #10
Keith Thompson wrote:
ja*********@verizon.net writes:
>Keith Thompson wrote:
>>sa**********@gmail.com writes:
[...]
>>>{
char i = NULL;
NULL is a null *pointer* constant. Assigning it to a char object
might happen to work, but it makes no sense. You probably mean
Given that it is C++ code, it will work. In C++, NULL has to have a
value of 0; it cannot have a pointer type.

True, but using NULL for anything other than a pointer value is poor
style in any case.
Agreed.
Dec 8 '07 #11

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

Similar topics

0
by: Chris McKeever | last post by:
I am trying to modify the Mailman Python code to stop mapping MIME-types and use the extension of the attachment instead. I am pretty much clueless as to what I need to do here, but I think I have...
18
by: Adrian B. | last post by:
Does anyone know of a framework or library that will enable me to use publish/subscribe comms? I want to create a server (using Python) running on a Unix box that will accept client connections...
3
by: masood.iqbal | last post by:
In this day and age, you never say no to any work that is thrown at you ---- so when I was offered this short-term contract to convert legacy C code to C++, I did not say no. Personally I believed...
5
by: brett valjalo | last post by:
Hey Gang! SORRY ABOUT THE LENGTH! Nice to see some of the same faces around this place from way back when ... Whatta buncha CDMA addicts some o' y'all are ;) Don't get me wrong, I...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
25
by: Alvin Bruney | last post by:
C# is great but it does have some short comings. Here, I examine one of them which I definitely think is a shortcoming. Coming from C++, there seems to be no equivalent in C# to separate code...
3
by: Rick | last post by:
I have a customer order form with a subform that lists parts per customer order that I'm updating. I'm trying to filer the parts list per Manufacture and Model number so that the user doesn't have...
66
by: Jon Skeet [C# MVP] | last post by:
I'm sure the net will be buzzing with this news fairly soon, but just in case anyone hasn't seen it yet: Microsoft are going to make the source code for the .NET framework (parts of it,...
29
by: Virtual_X | last post by:
As in IEEE754 double consist of sign bit 11 bits for exponent 52 bits for fraction i write this code to print double parts as it explained in ieee754 i want to know if the code contain any...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.