Thread: C Questions

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    4

    C Questions

    Can anyone help me with the following code and the questions that follow it?

    Code:
    LINE    Contains
    50    char * b, q, *r;
    200    b=getbuf();
    201    q = *b;
    212    r= anotherfunction(b);
    213-300    /* we want to use ‘q’ and  ‘r’ here*/
    2000    char * getbuf()
    2001    {
    2002       char buff[8];
    2003-2050  /* unspecified, buff defined here *./
    2051      return (char *) buff;
    2052    }
    What will be in variable ‘q’ after line 201 is executed? Under what conditions might this not be so?

    Is there an alternative, but equivalent, way to write line 2000? If so, what is it?

    Is getbuf() a reasonable function?

    Will getbuf() execute at all?

    Please comment on line 2051.

    Is getbuf() good practice, and why?

    What line not given should be provided for compilation?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Yeah, I've just answered all these on tek-tips.com.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM