Thread: A couple of theoretical questions about C

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    92

    A couple of theoretical questions about C

    Hello I have a couple theoretical question about the C programming language in general I will be highly obliged if anyone can answer them.

    Q1. Explain what the calloc() function does. Including the arguments it takes and the arguments it returns.

    Q2. All programs in C must have a function main() why is this the case?

    Q3. You attempt to creatre an excuatble program and the development tools inform you that there is an unresolved external symbol. Which tool is actually reporting this error and what does the error mean?

    Q4. If a programmer applies the "register" storage class to a variable, what does it mean? how does the compiler treat this storage class?

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Those are not "theoritical" questions, but Homework questions.

  3. #3
    Super Moderator Harbinger's Avatar
    Join Date
    Nov 2004
    Posts
    74
    Q1 - read the manual
    Q2 - write a program without main() and find out
    Q3 - ditto
    Q4 - ditto

  4. #4
    Registered User
    Join Date
    Sep 2005
    Location
    Sydney
    Posts
    60
    main() is where the program starts. Without main, how would it know where to begin? Would it just pick a random function and hope for the best? main() defines a starting point.

    The thing reporting your error would be the compiler. Any more detail than that probably depends on the specific compiler.

    The 'register' keyword is a hint to the compiler that that variable gets used a lot and should probably be stored in one of the CPUs registers. It's not used as much anymore as it used to be, since machines have become more efficient anyway so the performance gain is not as critical. Another reason for this is that compilers have become pretty good, so it's usually best to let the compiler work out how to optimise your code. As far as I know, 'register' isn't a strict requirement that the variable be stored in a register, just an indication to the compiler that it would be a good idea, which the compiler is free to ignore. I'm not 100% sure of that though, so you may want to check it.

    As for calloc(), I think that's definitely one you can look up, especially regarding its syntax. Basically it allocates space for an array and sets the memory to zero. The manpage should tell you anything else you need to know about it, or if not, google will.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    As far as I know, 'register' isn't a strict requirement that the variable be stored in a register, just an indication to the compiler that it would be a good idea, which the compiler is free to ignore
    Microsoft compilers ignore the register keyword.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Couple of questions about XOR linked lists...
    By klawson88 in forum C Programming
    Replies: 5
    Last Post: 04-19-2009, 04:55 PM
  2. Couple of simple directdraw questions.
    By Deo in forum Game Programming
    Replies: 3
    Last Post: 05-25-2005, 07:55 AM
  3. A couple of questions that someone might know the answer to...
    By Finchie_88 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 04-15-2005, 08:26 AM
  4. Studying for Final, Couple Questions...
    By stewade in forum C Programming
    Replies: 4
    Last Post: 05-10-2004, 05:02 PM
  5. New to C++/ Couple of questions...
    By danielthomas3 in forum C++ Programming
    Replies: 13
    Last Post: 04-14-2002, 03:46 PM