Re: A very **very** basic question



mdh said:

As I begin to write more little programs without the help of the
exercises, little things pop up that I need to understand more fully.
Thus, below, and although this is not the exact code, the principle of
the question is the same, ( I hope :-) )


#include <stdio.h>
int i = 0;
int main () { return 0; } /* no errors or warnings*/

but

#include <stdio.h>
int i ;

That's a declaration, and it's fine. It's also a tentative definition,
which is also fine.

i=0;

That's an assignment statement, which counts as code. You can't have code
outside a function.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.



Relevant Pages

  • Re: A very **very** basic question
    ... Thus, below, and although this is not the exact code, the principle of ... int i = 0; ... but I wish to understand the principle more clearly. ... you are allowed to declare and initialize objects outside of any ...
    (comp.lang.c)
  • A very **very** basic question
    ... exercises, little things pop up that I need to understand more fully. ... int i = 0; ... but I wish to understand the principle more clearly. ... the compiler thinks I am once again declaring 'i', ...
    (comp.lang.c)
  • Re: len() should always return something
    ... Some aspects of the Python design are remarkably clever, ... I admit I'm somewhat conflating this principle with the anti-ambiguity ... treats scalars as collections. ... represent an int (obviously breaks down a bit with arbitrary-magnitude ...
    (comp.lang.python)
  • Re: Struggling with K&R
    ... The exercises are impossible for me to do. ... It is easy to draw the histogram with the bars ... Now if we define a "word" as consecutive letters, ignoring awkward cases like "it's", and a non-word as anything that is not a letter, we can read the input character by character, and maintain two states. ... int main ...
    (comp.lang.c)
  • Re: A very **very** basic question
    ... int i = 0; ... but I wish to understand the principle more clearly. ... And external variables are ... Apparently there are no such things as global variables in C. Heathfield ...
    (comp.lang.c)

Loading