Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Code Effect

Reply
Thread Tools

Code Effect

 
 
Daniel Antonson
Guest
Posts: n/a
 
      07-03-2005
What is the effect of the following code?

char Ch;

Ch = '7';

printf("%d\n", Ch);


 
Reply With Quote
 
 
 
 
Daniel Antonson
Guest
Posts: n/a
 
      07-03-2005
The choices available are:

a. It will cause an error

b. It will print out the computer's internal code for the character '7'

c. It will print out the character '7'

d. It will print out the character whose internal code is 7


"Daniel Antonson" <> wrote in message
news:QoidnehXbYGD9lrfRVn-...
> What is the effect of the following code?
>
> char Ch;
>
> Ch = '7';
>
> printf("%d\n", Ch);
>
>



 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      07-03-2005
In article <-_2dnTq1Ad8c8VrfRVn->,
Daniel Antonson <> wrote:
>"Daniel Antonson" <> wrote in message
>news:QoidnehXbYGD9lrfRVn-...
>> What is the effect of the following code?


>> char Ch;


>> Ch = '7';


>> printf("%d\n", Ch);



>The choices available are:


>a. It will cause an error


Yup. You can't call a function at file scope, so the code will
not compile as-is.
--
"Who Leads?" / "The men who must... driven men, compelled men."
"Freak men."
"You're all freaks, sir. But you always have been freaks.
Life is a freak. That's its hope and glory." -- Alfred Bester, TSMD
 
Reply With Quote
 
Mac
Guest
Posts: n/a
 
      07-03-2005
On Sun, 03 Jul 2005 00:41:37 -0400, Daniel Antonson wrote:

> The choices available are:
>
> a. It will cause an error
>
> b. It will print out the computer's internal code for the character '7'
>
> c. It will print out the character '7'
>
> d. It will print out the character whose internal code is 7
>
>
> "Daniel Antonson" <> wrote in message
> news:QoidnehXbYGD9lrfRVn-...
>> What is the effect of the following code?
>>
>> char Ch;
>>
>> Ch = '7';
>>
>> printf("%d\n", Ch);
>>
>>


Which one did you choose?

--Mac

 
Reply With Quote
 
sandeep
Guest
Posts: n/a
 
      07-03-2005
Answer will be 'b'
It will print out the computer's internal code for the character '7'

 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      07-03-2005
In article <. com>,
sandeep <> wrote:
:Answer will be 'b'

What answer will be 'b'? You didn't quote any establishing context.

:It will print out the computer's internal code for the character '7'

Obviously you didn't try it.

$ gcc -std=c89 -pedantic -o seven seven.c
seven.c:3: error: conflicting types for `Ch'
seven.c:1: error: previous declaration of `Ch'
seven.c:3: error: ISO C forbids data definition with no type or storage class
seven.c:5: error: parse error before string constant
seven.c:5: warning: conflicting types for built-in function `printf'
seven.c:5: error: ISO C forbids data definition with no type or storage class

$ gcc -std=c99 -pedantic -o seven seven.c
seven.c:3: warning: type defaults to `int' in declaration of `Ch'
seven.c:3: error: conflicting types for `Ch'
seven.c:1: error: previous declaration of `Ch'
seven.c:3: error: ISO C forbids data definition with no type or storage class
seven.c:5: error: parse error before string constant
seven.c:5: warning: type defaults to `int' in declaration of `printf'
seven.c:5: warning: conflicting types for built-in function `printf'
seven.c:5: error: ISO C forbids data definition with no type or storage class

$ : SGI IRIX below

$ cc -o seven -fullwarn seven.c
cc-1077 cc: ERROR File = seven.c, Line = 3
The indicated declaration has no storage class or type specifier.

Ch = '7';
^

cc-1143 cc: ERROR File = seven.c, Line = 3
Declaration is incompatible with "char Ch" (declared at line 1).

Ch = '7';
^

cc-1079 cc: ERROR File = seven.c, Line = 5
A type specifier is expected.

printf("%d\n", Ch);
^

cc-1079 cc: ERROR File = seven.c, Line = 5
A type specifier is expected.

printf("%d\n", Ch);
^

cc-1077 cc: WARNING File = seven.c, Line = 5
The indicated declaration has no storage class or type specifier.

printf("%d\n", Ch);
^

4 errors detected in the compilation of "seven.c".

--
Any sufficiently advanced bug is indistinguishable from a feature.
-- Rich Kulawiec
 
Reply With Quote
 
Michel Rouzic
Guest
Posts: n/a
 
      07-03-2005


Daniel Antonson wrote:
> What is the effect of the following code?
>
> char Ch;
>
> Ch = '7';
>
> printf("%d\n", Ch);


idk, seems obvious to me that it prints the ascii value of '7'. is it a
question to tell newbies in C from others?

 
Reply With Quote
 
sandeep
Guest
Posts: n/a
 
      07-03-2005


Walter Roberson wrote:
> In article <. com>,
> sandeep <> wrote:
> :Answer will be 'b'
>
> What answer will be 'b'? You didn't quote any establishing context.
>
> :It will print out the computer's internal code for the character '7'
>
> Obviously you didn't try it.

What made u think that i didn,t tried that
I tried and i got "55" as the internal value of '7'.
Which is also the ASCII value for "7".
Now i got it correct and you might be having some problem with your
compiler or you missed something.
anyways be careful in future.
>
> $ gcc -std=c89 -pedantic -o seven seven.c
> seven.c:3: error: conflicting types for `Ch'
> seven.c:1: error: previous declaration of `Ch'
> seven.c:3: error: ISO C forbids data definition with no type or storage class
> seven.c:5: error: parse error before string constant
> seven.c:5: warning: conflicting types for built-in function `printf'
> seven.c:5: error: ISO C forbids data definition with no type or storage class
>
> $ gcc -std=c99 -pedantic -o seven seven.c
> seven.c:3: warning: type defaults to `int' in declaration of `Ch'
> seven.c:3: error: conflicting types for `Ch'
> seven.c:1: error: previous declaration of `Ch'
> seven.c:3: error: ISO C forbids data definition with no type or storage class
> seven.c:5: error: parse error before string constant
> seven.c:5: warning: type defaults to `int' in declaration of `printf'
> seven.c:5: warning: conflicting types for built-in function `printf'
> seven.c:5: error: ISO C forbids data definition with no type or storage class
>
> $ : SGI IRIX below
>
> $ cc -o seven -fullwarn seven.c
> cc-1077 cc: ERROR File = seven.c, Line = 3
> The indicated declaration has no storage class or type specifier.
>
> Ch = '7';
> ^
>
> cc-1143 cc: ERROR File = seven.c, Line = 3
> Declaration is incompatible with "char Ch" (declared at line 1).
>
> Ch = '7';
> ^
>
> cc-1079 cc: ERROR File = seven.c, Line = 5
> A type specifier is expected.
>
> printf("%d\n", Ch);
> ^
>
> cc-1079 cc: ERROR File = seven.c, Line = 5
> A type specifier is expected.
>
> printf("%d\n", Ch);
> ^
>
> cc-1077 cc: WARNING File = seven.c, Line = 5
> The indicated declaration has no storage class or type specifier.
>
> printf("%d\n", Ch);
> ^
>
> 4 errors detected in the compilation of "seven.c".
>
> --
> Any sufficiently advanced bug is indistinguishable from a feature.
> -- Rich Kulawiec


 
Reply With Quote
 
sandeep
Guest
Posts: n/a
 
      07-03-2005
As it will print the ASCII value of '7' which is 55

 
Reply With Quote
 
sandeep
Guest
Posts: n/a
 
      07-03-2005


sandeep wrote:
> Answer will be 'b'
> It will print out the computer's internal code for the character '7'

As it will print the ASCII value of '7' which is 55

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding proper functionality to code.Please read comments in code andfirst test it in your browser to see the effect. Mclaren Fan Javascript 2 11-08-2011 05:50 PM
Funny side effect of js code seebach Javascript 0 07-05-2007 02:22 PM
Cuffs - code and effect comment? Dr J R Stockton Javascript 4 06-07-2007 01:48 PM
Code without effect (wx demo TreeCtrl.py ImageList) Martin Drautzburg Python 2 12-20-2004 06:16 PM
Re: Flickering effect SEWilson ASP .Net 0 08-23-2003 03:59 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57