473,386 Members | 1,699 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.

why it is not giving any error?

hi all,
I have executed the following program, I was expecting some errors in
the program but it didn't give any ERRORS!!!!!!!!!!!!!!!!!!!!!!!!!!!
please can anybody explain me ?
#include<stdio.h>
int main()
{
char a=97;

"hello everyone"+printf("value of a=%c\n",a);
return 0;
}

Thanks in advance
Prasanna K P

Nov 15 '05 #1
12 1655
prasi wrote:
hi all,
I have executed the following program, I was expecting some errors in
the program but it didn't give any ERRORS!!!!!!!!!!!!!!!!!!!!!!!!!!!
please can anybody explain me ?
#include<stdio.h>
int main()
{
char a=97;

"hello everyone"+printf("value of a=%c\n",a);
return 0;
}


Adding an integer to a character pointer is a well defined operation (It
has no side effect in your example though.) For instance:

char *s = "xyz";

printf("%c\n", *(s + 2));

will output 'z'.
August
Nov 15 '05 #2
> #include<stdio.h>
int main()
{
char a=97;


You have assigned a decimal value of 97 to char variable 'a'. This
infact is legal in C as characters use ascii conversion. Not too sure
about why, but if you type in google, "ascii code" you will see
decimals numbers assigned to each character.

Nov 15 '05 #3
prasi wrote:
hi all,
I have executed the following program, I was expecting some errors in
the program but it didn't give any ERRORS!!!!!!!!!!!!!!!!!!!!!!!!!!!
please can anybody explain me ?
#include<stdio.h>
int main()
{
char a=97;

"hello everyone"+printf("value of a=%c\n",a);
return 0;
}


There's nothing wrong with the code.

It's /stupid/, but there's no obligation on a compiler to detect
stupid code.

97 is legal as a character value (ill-advised, but legal).

Adding integers to pointers is legal - C would be pretty useless if
it were not - and ignoring calculated values is also legal and
often useful.

You might get some messages if you poked your compiler options a
bit harder.

--
Chris "electric hedgehog" Dollin
"I know three kinds: hot, cool, and what-time-does-the-tune-start?"
Nov 15 '05 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David G. Hong wrote:
#include<stdio.h>
int main()
{
char a=97;

You have assigned a decimal value of 97 to char variable 'a'. This
infact is legal in C


True so far.
as characters use ascii conversion.


Untrue.

The C standard -does not_ specify which characterset is used, and standard C has
been implemented in other charactersets other than ASCII.

On the platforms that I use,
char a=97;

assigns the variable a the value associated with the SOLIDUS ('/') character.
Needless to say, the characterset is _not_ ASCII.

[snip]
- --
Lew Pitcher
IT Specialist, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFDQSxoagVFX4UWr64RAilkAJ9JbGQrOAzGt2JhdU6mMz f0WMeeQQCfU2T6
p3reCWQNcscJ1atN1kKGqkw=
=7X04
-----END PGP SIGNATURE-----
Nov 15 '05 #5
Lew Pitcher wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David G. Hong wrote:
#include<stdio.h>
int main()
{
char a=97;

You have assigned a decimal value of 97 to char variable 'a'. This
infact is legal in C


True so far.
as characters use ascii conversion.


Untrue.


It's legal because CHAR_MAX is guaranteed to be at least 127,
and CHAR_MIN is guaranteed to be no greater than zero.

--
pete
Nov 15 '05 #6
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

pete wrote:
Lew Pitcher wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David G. Hong wrote:
#include<stdio.h>
int main()
{
char a=97;
You have assigned a decimal value of 97 to char variable 'a'. This
infact is legal in C


True so far.

as characters use ascii conversion.


Untrue.

It's legal because CHAR_MAX is guaranteed to be at least 127,
and CHAR_MIN is guaranteed to be no greater than zero.


Which is entirely irrelevant to this thread.

The issue is whether or not "characters use ascii conversion" is a valid
statement, not whether 97 is a value between CHAR_MIN and CHAR_MAX.

- --
Lew Pitcher
IT Specialist, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFDQUoiagVFX4UWr64RAv5oAJ9ReVwkOzQ0DL1EtiZ26r RdO4oqfQCgj4MA
BppF/jnyGH+ABHvOMYJY+5I=
=eZ5q
-----END PGP SIGNATURE-----
Nov 15 '05 #7
Lew Pitcher wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

pete wrote:
Lew Pitcher wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David G. Hong wrote:

>#include<stdio.h>
>int main()
>{
>char a=97;
You have assigned a decimal value of 97 to char variable 'a'. This
infact is legal in C

True so far.
as characters use ascii conversion.

Untrue.

It's legal because CHAR_MAX is guaranteed to be at least 127,
and CHAR_MIN is guaranteed to be no greater than zero.


Which is entirely irrelevant to this thread.


No. The subject line is:
why it is not giving any error?

The reason why
char a=97;
is not giving any error, was attempted by David G. Hong.

I gave the correct reason.

ASCII is irrelevant to OP's question.

--
pete
Nov 15 '05 #8
prasi wrote:
hi all,
I have executed the following program, I was expecting some errors in
the program but it didn't give any ERRORS!!!!!!!!!!!!!!!!!!!!!!!!!!!
please can anybody explain me ?
No one can explain you. Let's get back to your code. What errors were
you expecting? Why? You would learn more from examining your false
expectations. Asking us to explain all the errors *not* in this code is
silly: that list would be inexhaustible.

And what makes you think wanton repetition of exclamation marks
accomplishes anything?
#include<stdio.h>
int main()
{
char a=97;

"hello everyone"+printf("value of a=%c\n",a);
return 0;
}

Thanks in advance
Prasanna K P

Nov 15 '05 #9
David G. Hong wrote:
#include<stdio.h>
int main()
{
char a=97;

You have assigned a decimal value of 97 to char variable 'a'. This
infact is legal in C as characters use ascii conversion.


It is legal to assign to a char any value in the range CHAR_MIN to
CHAR_MAX. This has nothing to do with the character sets used.
There is nothing that specifies that C use ASCII (note caps). The word
'conversion' is a bit off the mark as well.
Nov 15 '05 #10
Martin Ambuhl <ma*****@earthlink.net> wrote:
It is legal to assign to a char any value in the range CHAR_MIN to
CHAR_MAX.


Does it matter whether the char in question is signed or unsigned?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 15 '05 #11
Christopher Benson-Manica wrote:
Martin Ambuhl <ma*****@earthlink.net> wrote:
It is legal to assign to a char any value in the range CHAR_MIN to
CHAR_MAX.


Does it matter whether the char in question is signed or unsigned?


Not for the truth of Martin's statement, nor for the assignment of 97.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #12
Christopher Benson-Manica wrote:
Martin Ambuhl <ma*****@earthlink.net> wrote:

It is legal to assign to a char any value in the range CHAR_MIN to
CHAR_MAX.

Does it matter whether the char in question is signed or unsigned?


a char is in the range CHAR_MIN to CHAR_MAX,
a signed char is in the range SCHAR_MIN (-127 or less) to SCHAR_MAX
(+127 or more)
an unsigned char is in the range 0 to UCHAR_MAX (+255 or more)

The OP's code used 97, which is always in range for a char, signed char,
or unsigned char. He initialized a char with this value, so only
CHAR_MIN and CHAR_MAX are relevant.
Nov 15 '05 #13

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

Similar topics

10
by: Lakshmi Narayanan.R | last post by:
Hi Experts, Using keyword "To" in select case giving error.The following code is got from www.microsrosoft.com itself. What is the wrong with this?. <% Dim Number1 Number1 = 7 ' Initialize...
1
by: laurenq uantrell | last post by:
I'm trying to figure out why I can't loop through a function (myFunctionXYZ) after an error. The problem is that I can loop from the error once back into the code section of myFunctionXYZ, but on...
0
by: sandeep pandit via .NET 247 | last post by:
hello sir, i read your article on URL rewriting in asp.net on msdn.i have also used the same in my project.URL rewriting is working fine in our LAN and on our configured IP but problem is that...
3
by: Simon | last post by:
This problem has been driving me mad for months.... Seen a few posts on forums about it but no answers... No mention on MSDN etc. XP Pro SP1, VS.NET (c#) .Net framework 1.1, IIS 5.1. In a...
2
by: edsuslen | last post by:
I am migrating working code (HTTPRequest with Authentication) from vb to vb.net vb: Set objXMLHTTPServer = New MSXML2.XMLHTTP30 objXMLHTTPServer.Open strMethod, strGetRequest, False, "UserId",...
5
by: washoetech | last post by:
Hello, I have tried to run my ASP.NET 2.0 application from IIS and I get a page not found error. When I debug from within Visual Studio.NET 2005 my application works fine. Any ideas? ...
1
by: connoisseur.infotech | last post by:
i have schedule a .exe of VB6.0 on a remote computer and when that exe run out i got this message in scheduler. operating system is window server 2003 where i have scheduled it. This program...
7
by: John Øllgård Jensen | last post by:
Hi Using MS Asccess 2000: In a query I'm trying to create a new field with following expression: FilmDate: Left(,4) The field "FilmNo" is another text field in the query. This is...
1
by: Rahul Bhate | last post by:
Hello Sir My problem is in dos giving error that javac is not recognised.Tell me the steps for debugging.I have already set the CLASSPTH through command line & also set the PATH.But still giving...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.