Some interesting novice questions from a novice guy

scott at max.u.washington.edu scott at max.u.washington.edu
Wed Oct 24 22:49:23 AEST 1990


Hello, I am a novice C program and such my head is spinning with
questions that are screaming to be answer, otherwise will drive me to
the point of insanity... in turn, hopefully I will not be driving you
insane with "much asked" dull quesitions. Thanks in advance.
 
 
Some specific question:
 
 
Example 1:                               Example 2:
 
        for (i=0; i<10; i++)             for (i=0; i<10; ++i)
        {                                {
           <first statement>               <first statament>
             "        "                      "         "
             "        "                      "         "
           <last  statement>               <last  statement>
        }                                }
 
In example 1, when does the value of "i" gets incremented?
     My guess is after the <last statement> in the block has been
     executed. But I want to be sure.
In example 2, the same question.
     My guess in this one is after "i<10".
 
 
Example 3:                                         
 
        while (*ptr++);                  while (*ptr)
                                           ptr++;
 
In example 3, do the two pieces of codes are equivalent?
 
 
Example 4:
 
        void test(char str[])            void test(char *str)
 
In example 4, do the two pieces of codes are interchangeable?
 
 
 
And lastly, I have one general question.
It has to do with types. In other computer languages like ADA and PASCAL
mixing different types in a expression or assigning the content of
one type of variable to a different type of variable is a no no.
This doesn't mean that you can't use, for example, an integer value in an
expression with reals, but you must first convert the integer value to a     
real format (through a function) before using it with other reals.
But C doesn't seems to fall into this rule. Character variables can
be treated as integers and also "=" to and from a integer. Same thing
goes with unsigned variables. But integers occupy two bytes while
characters only one. So when you int "=" char, what value will get
store in the higher byte of the int? How about with integer and
unsigned? If I am only dealing with positive numbers, there is no
difference between the two? If I write char "=" 65 instead of 'A',
is that a normal way of doing it or bad practice. How about when
the function returns a value 1 to 5, should I make the function's
return type an integer or an unsigned or even a character?
 
 
I will appreciate you help
 
 
Sincerely,
Scott K. Stephen



More information about the Comp.lang.c mailing list