Re: Urgent C Questions



On Tue, 15 Jan 2008 03:41:56 +0100 (CET), Hans Schneider
<hans@xxxxxxxxxxxxxxxxxxxxx> wrote in comp.lang.c:

For it to be a C question, urgent or not, it would have to be about
valid C code.

1. in the prg bellow what vars are stored on stack, heap, data segment?

int i;

void main()

The line above generates undefined behavior, not valid C code.

{
int j;
int *k = (void *)malloc(1);

Since there is no prototype for malloc() in scope, undefined behavior,
not valid C code.

}

(I think j and k are on stack, but where is i?)


2. how to find sizeof variable w/o using sizeof command?

(no clue)

There is no sizeof command, not a valid C question.

3. what is the o/p of this prg?

void main()

The line above generates undefined behavior, not valid C code.

{
int x = 5;
x = x++;

The line above generates undefined behavior, not valid C code.

printf("x=%i", x);

Since there is no prototype for printf() in scope, this causes
undefined behavior, not valid C code.

}

(I think it shoulld be printing 5 but it prints 6!)

I think it should print, "This code was written by an idiot!".

ps: I am using QuickC 2.0

pps: Is very urgent!

Sorry, non of these is a question about the C language. If you are in
an actual C programming course, and your instructor asked these
questions for a homework assignment, do the following:

1. Immediately drop the class.

2. Complain to the school administration about the unqualified
instructor and erroneous material.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
.



Relevant Pages

  • Re: Function call evaluation order
    ... void f1 ... int i = 0; ... f1 has.completely undefined behavior since i is modified twice ...
    (microsoft.public.vc.language)
  • Re: Function call evaluation order
    ... void f1 ... int i = 0; ... has.completely undefined behavior since i is modified twice between ...
    (microsoft.public.vc.language)
  • Re: Function call evaluation order
    ... void f1 ... int i = 0; ... has.completely undefined behavior since i is modified twice between ...
    (microsoft.public.vc.language)
  • Re: C free
    ... int *p; ... If you fix that (by casting to `void *`), ... It's the dereferencing the dud pointer that causes UB, ... at the value of an indeterminate pointer invokes undefined behavior. ...
    (comp.lang.c)
  • Re: Urgent C Questions
    ... void main ... how to find sizeof variable w/o using sizeof command? ... pps: Is very urgent! ...
    (comp.lang.c)