A very long list of questions... maybe to long...

This is a discussion on A very long list of questions... maybe to long... within the C Programming forums, part of the General Programming Boards category; I have been reading two c tutorial books and getting help from a reference book. So far in each I ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    45

    Question A very long list of questions... maybe to long...

    I have been reading two c tutorial books and getting help from a reference book. So far in each I am able to work my way to about halfway through each until I get to sections on arrays and pointers, once I get to that point I find myself not able to understand anything. Through trying to figure out why I have found that I don't have a deep enough comprehension of the c language. I have came up with a list of questions that I would like anyone who can to answer them, if they would be so kind (= I've looked up these questions on my own I have found some results but I'm unsure of what I have learned to be an accurate interpretation of the facts so I shall list my questions, say what I think the answer is (if I have any idea of it) and I'll list any relevant information that I have found on my own. OK... So here are the questions:

    What is an algorithm / what do people by algorithm?:
    OK this may be a very basic question... but I have to start somewhere. The definition that I have is as follows "The formula or procedure by which a set of program instructions performs a defined task" That seems very easy to understand something that does a defined task, OK. Well my question really is what do people mean by an algorithm, for example I may be told that I need to rethink my algorithm out, well in my head that would mean my program so, does algorithm == program? since a program does a defined thing right...?

    An argument?:
    "The value passed to a function or subroutine. Its type must match that of the corresponding parameter in the declaration."
    Well this one has me stumped. According to that this is a argument:
    Code:
    print("%d", variable");
    where the variable is the argument, so by that am I right in assuming that anything that modifies a function is a argument also is there thing else besides the above that is considered an argument and can an argument have any other forms?

    Don't use auto?
    This one in a weird way makes me unhappy, there is a keyword that there is no point in using (according to my 3 books and several tutorials). From what I have learned the auto keyword is used as a to declare a variables type, when used it would create a "local variable that loses its value as it goes out of scope" or in my words a plain old local variable.
    OK so i have a few questions about this one, is there a way that I can make use of this keyword, if the answer is no... Why would someone create something unusable (I'm assuming it may have been used in earlier versions of C?)

    And my last question is on this is about Automatic variables / local variables, when these variables lose they're value apron leaving the function that they are declared, are they really lost or just lost to the rest of the program, for example, if i was to use goto or some do something to make a loop that would reenter the function would the variables value contain what it did when I was there last or be given the initialized value. Maybe I should give a code example...Or at least pseudo code
    Code:
    main(){
    somefunction() {
    int variable = 0;
    repate:
    variable++
    }
    goto repeate;
    }
    32 bit vs 64 bit:
    I've heard some talk about this in regarding to programming, it seems that depending on your computers "architecture" the values when declaring variables may differ depending on what type of computer you are using. My questions regarding this issue are: How do I tell what type of "architecture" (I don't really know what that means...) does my computer use (=, i wonder if i should already know that, lol.
    Are they're any other differences that would make porting programs difficult (differences in regarding this question, not about the lack of some libraries and other issues, I'll ask about that in a bit (=.

    <expression1> ? <expression2> : <expression3> ?
    well my question on this is why doesn't anyone use this (from what I've looked at it I've never seen any one use it) it looks like a good way to control the programs flow.
    BTW just because I like it doesn't mean I can use it...
    Please tell me why the following program doesn't work )=
    Code:
    #include <stdio.h>
    int main(void)
    {
    int variable;
    scanf("d%", &variable);
    variable ? printf("false\n") : printf("true\n");
    return 0;
    }
    Arrays and pointers?
    OK i've decided these things are the reincarnation of the devil! These things are why I decided to make this list of questions...
    OK what I don't understand about them is:
    Pointers, why would you need / care about where something is located. I make a variable the computer makes room for the variable, I give it a value and the computer remembers it... So why after all that do we care where exactly at where it is located.
    And how do you use pointers )= I think I can make a 1 dimensional array fine. but pointers they are a mystery )= Of course so are 2 dimensional arrays.
    One more question on this it seems that with each dimension an array is given the more memory they require, at what point (how many dimensions) would be to much?

    File scope?
    So theres global variables (entire program can use) local (Used within the function) external (from outside the program) and static (only within the program, can't be used outside it). I hope I got those right, my question in regards to these (I get local and global) is why would you need to declare static wouldn't it be better to just make sure your variables from other files (you intend to use / merge with this one) have separate variable names, would that solve the problems you may have?

    return?
    I understand why main() should have a return, but what about all other functions.

    Headers?
    Why can't I find them )= I would like to take a look at them but don't know where to do so...
    When headers are added to files, are they completely added if you wanted to use printf() by adding <stdio.h> would you add the entire thing or only what deals with print()?
    If I would like to make my own printf() is it possible by using only the 32 c keywords? *very important. I must know (= *

    Hexadecimal base/octal?
    My only question is why use them? They seem to only confuse things, I mean you can't read them as easy as you can with regular numbers or can you? OK... so why use them (=

    Macro:
    What is a macro...? Some one mentioned it while talking about programming so I thougth I'd ask.
    Well that's all i have for that one, (=

    C != graphics?
    So it seems that all c can do is simple printing to the terminal screen )= Is there any way to make a window or anything nice looking (=
    If I ever did want to add graphics to my programs would I have to learn c++
    On this note what is C not good for, what would you never make a program in with c?

    lvalue and rvalue?
    My compiler laughs at me and says I have an error with the above words...
    So my first question is whats the command to force my computer to throw itself out a window... (=
    These only deal with improperly using variables, putting values on wrong side etc. right?

    Parameter = Argument?
    What is the main difference between the two?

    Recursion:
    So I can make a function call itself? That sounds very "interesting" so how would I do that and what would my intention be if I did?

    Memory Buffer?
    I'm sure this is an easy one to look up, but if anyone would please tell me what it is and how it affects my programs I would be very grateful (=

    Well I had at least 20 other questions but... I think I wont post them (=
    We'll see if my first comment is "google" (=

    I appreciate any help/insight into the above questions.
    Thanks in advance for any help that you can give
    BTW my first checking of this I got 70 mispellings (= I tried to get rid of them to make it easier to understand my questions forgive me if I missed some )=
    -Raven'sWrath

  2. #2
    Registered User
    Join Date
    May 2007
    Posts
    45
    I think I'll answer one of my own questions... (=

    What is a macro?
    A macro is a tool that programmers use so they don't have to type long names of commands, macros should be used to save you time or to help you avoid errors as the following macro would do:

    Code:
     
    #include <stdio.h>
    #define EQ ==  /* macro */
    int main(void) {
     int a, b;
     a = 1;
     b = 1;
       if (a EQ b){
       printf("a and b are evaluated to be equal\n");
                       }
    return 0;
    }
    that code would make it so you wouldn't get = and == mixed up when coding.


    Anyone know how to make the linker link my files together, I'm thinking about making a "cheat sheet" so I don't have to type out all my macros and main(), and my headers each time.
    Thanks

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,306
    that code would make it so you wouldn't get = and == mixed up when coding
    I think that the benefits are dubious, since such introduction of new fundamental syntax can become a form of obfuscation.

    Well my question really is what do people mean by an algorithm, for example I may be told that I need to rethink my algorithm out, well in my head that would mean my program so, does algorithm == program?
    Your program would implement an algorithm.

    where the variable is the argument, so by that am I right in assuming that anything that modifies a function is a argument also is there thing else besides the above that is considered an argument and can an argument have any other forms?
    An argument is something passed to a function via its parameters.

    Parameter = Argument?
    What is the main difference between the two?
    A parameter is the variable name, an argument is what is passed. Generally, I do not distinguish too much between the two.

    there is a keyword that there is no point in using
    C has a long history. Try to be modern.

    <expression1> ? <expression2> : <expression3> ?
    well my question on this is why doesn't anyone use this (from what I've looked at it I've never seen any one use it) it looks like a good way to control the programs flow.
    It is equivalent to an if-else structure, though more prone to obfuscation. If you do use it, my advice is to avoid nesting it within other ternary conditional operators.

    Hexadecimal base/octal?
    My only question is why use them? They seem to only confuse things, I mean you can't read them as easy as you can with regular numbers or can you? OK... so why use them (=
    They are a shorthand for binary, which happens to be what computers use.

    Pointers, why would you need / care about where something is located. I make a variable the computer makes room for the variable, I give it a value and the computer remembers it... So why after all that do we care where exactly at where it is located.
    Amazingly, we have a tutorial titled An introduction to pointers, and its first subheading is "What are pointers? Why should you care?".

    This brings me to my next point: have you actually read the tutorials on cprogramming.com?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    45
    I very much appreciate your reply, thank you (=


    Your program would implement an algorithm.
    Right, but I'm more interested in what exactly in the program that would be considered the algorithm unless of course the program itself is considered in algorithm than... I'll just call it a program from now on (=

    A parameter is the variable name, an argument is what is passed. Generally, I do not distinguish too much between the two.
    So does that mean I can program and not have to worry or understand the difference between the two (=, thats fine by me I don't like remembeing new definitions (=

    C has a long history. Try to be modern.
    Ok, maybe I'll throw in the keywords occasionally for remeberence of its history than ( ;

    It is equivalent to an if-else structure, though more prone to obfuscation. If you do use it, my advice is to avoid nesting it within other ternary conditional operators.
    Ah I see, well in some cases it may come in handy, btw I had to look up obfuscation, lol :P

    They are a shorthand for binary, which happens to be what computers use.
    Well... I knew that much, but why need it isn't the purpose of c so you don't have to "talk" to a computer at its most fundamental level?

    Amazingly, we have a tutorial titled An introduction to pointers, and its first subheading is "What are pointers? Why should you care?".

    This brings me to my next point: have you actually read the tutorials on cprogramming.com?
    Ok I should have checked the tutorials on that question (=
    I've read some of them

    Thanks again

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,306
    Right, but I'm more interested in what exactly in the program that would be considered the algorithm unless of course the program itself is considered in algorithm than... I'll just call it a program from now on (=
    Consider an algorithm to find the maximum element in an array of numbers. The array has n elements, where n guaranteed to be positive. We might write out the algorithm in words, as a kind of pseudocode:
    Code:
    Take the first element to be the current known maximum
    Loop over the rest of the array
        If the current known maximum is less than the current element
            The current element is the current known maximum
    That surely will not compile in C, or in any programming language I can think of. But you can implement it in C:
    Code:
    max = array[0];
    for (i = 1; i < n; ++i)
    {
        if (max < array[i])
        {
            max = array[i];
        }
    }
    Then again, you might want to find the index of the maximum element instead of its value. The algorithm remains pretty much the same, but the implementation is tweaked:
    Code:
    max = 0;
    for (i = 1; i < n; ++i)
    {
        if (array[max] < array[i])
        {
            max = i;
        }
    }
    Well... I knew that much, but why need it isn't the purpose of c so you don't have to "talk" to a computer at its most fundamental level?
    Abstractions leak, and in other times bitwise operations come in handy. That said, magic numbers, regardless of the base they are expressed in, are usually better off as named constants instead of magic numbers.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Day Dreamer
    Join Date
    Apr 2007
    Posts
    45
    I will answer three of your questions now.

    It is not that the auto keyword cannot be used at all. It is recommended by your books and tutorials not to use the keyword as it is added by the compiler by default when you dont specify anything else.
    For example if you write
    int i = 10;
    By default it means auto int i=10;
    So you dont need to use "auto"
    Not that you cant use it.


    Algorithms!
    Well a program implements an algorithm in the language you write the program.
    An algorithm may essentially be thought of as the
    well defined steps to do a particular task.
    For example:
    If you want to buy a computer the steps would be:
    Step 1: Save enough money
    Step 2: Decide what configuration, brand etc you want to buy.
    Step 3: Go to a shop.
    Step 4: Get your computer.

    This forms an algorithm.
    It is actually the breakdown of the steps you want to take in order to perform a particular task.

    When you go out of the scope of a function the variables declared in the function do not retain
    their value.
    If you want them to retain the value then you may want to declare them globally which is not recommended for extensive usage or may be use the static keyword which again has limitations of its own.

    I will go through your other questions and reply later!
    Till them happy learning!

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by Ravens'sWrath View Post
    I have been reading two c tutorial books and getting help from a reference book. So far in each I am able to work my way to about halfway through each until I get to sections on arrays and pointers, once I get to that point I find myself not able to understand anything. Through trying to figure out why I have found that I don't have a deep enough comprehension of the c language. I have came up with a list of questions that I would like anyone who can to answer them, if they would be so kind (= I've looked up these questions on my own I have found some results but I'm unsure of what I have learned to be an accurate interpretation of the facts so I shall list my questions, say what I think the answer is (if I have any idea of it) and I'll list any relevant information that I have found on my own. OK... So here are the questions:

    What is an algorithm / what do people by algorithm?:
    OK this may be a very basic question... but I have to start somewhere. The definition that I have is as follows "The formula or procedure by which a set of program instructions performs a defined task" That seems very easy to understand something that does a defined task, OK. Well my question really is what do people mean by an algorithm, for example I may be told that I need to rethink my algorithm out, well in my head that would mean my program so, does algorithm == program? since a program does a defined thing right...?
    An algorithm is just the steps your program goes through, to do it's work. If your algorithm is wrong, no matter how well the rest of your program's output or performance might be, the program will not complete it's work, accurately.

    Think of the steps you go through to go to work or school in the morning: wake up, clean up, get dressed, grab a bit of breakfast, get in your car and drive to work. Each is a step that would contain several steps of it's own. Some could be left out, like breakfast, but waking up is an essential step in the algorithm. Not only do you have to wake up, but you have to wake up *first*, before you can get anything else done.

    An argument?:
    "The value passed to a function or subroutine. Its type must match that of the corresponding parameter in the declaration."
    Well this one has me stumped. According to that this is a argument:
    Code:
    print("%d", variable");
    where the variable is the argument, so by that am I right in assuming that anything that modifies a function is a argument also is there thing else besides the above that is considered an argument and can an argument have any other forms?
    I don't think of an argument as modifying a function. I think of it as a little house warming gift, you're delivering to the function. The function must know how to respond to that gift, and since the eyesight ain't what it used to be, you tell it what kind of a housewarming gift it is that you've brought today. Flowers get dunked in a vase of water - but a CD would not!

    Don't use auto?
    This one in a weird way makes me unhappy, there is a keyword that there is no point in using (according to my 3 books and several tutorials). From what I have learned the auto keyword is used as a to declare a variables type, when used it would create a "local variable that loses its value as it goes out of scope" or in my words a plain old local variable.
    OK so i have a few questions about this one, is there a way that I can make use of this keyword, if the answer is no... Why would someone create something unusable (I'm assuming it may have been used in earlier versions of C?)
    Remember that C didn't just arise out of thin air. It was based on 'B', but included other idea's as well. The idea of "auto" was found overwhelmingly useful and popular, and made the default. I believe this was done in the early prototype of the language.

    And my last question is on this is about Automatic variables / local variables, when these variables lose they're value apron leaving the function that they are declared, are they really lost or just lost to the rest of the program, for example, if i was to use goto or some do something to make a loop that would reenter the function would the variables value contain what it did when I was there last or be given the initialized value. Maybe I should give a code example...Or at least pseudo code
    Code:
    main(){
    somefunction() {
    int variable = 0;
    repate:
    variable++
    }
    goto repeate;
    }
    The result would vary from compiler to compiler, and OS to OS, but it would not be something you could rely on. When they talk about "undefined behavior", that's pretty much a euphemism for "you're totally goofed!"


    32 bit vs 64 bit:
    I've heard some talk about this in regarding to programming, it seems that depending on your computers "architecture" the values when declaring variables may differ depending on what type of computer you are using. My questions regarding this issue are: How do I tell what type of "architecture" (I don't really know what that means...) does my computer use (=, i wonder if i should already know that, lol.
    The values differ in size, perhaps, but shouldn't differ in value when you declare a variable to be some value. Int i = 0, is still going to get i equal to zero, regardless.

    Are they're any other differences that would make porting programs difficult (differences in regarding this question, not about the lack of some libraries and other issues, I'll ask about that in a bit (=.

    <expression1> ? <expression2> : <expression3> ?
    well my question on this is why doesn't anyone use this (from what I've looked at it I've never seen any one use it) it looks like a good way to control the programs flow.
    BTW just because I like it doesn't mean I can use it...
    Please tell me why the following program doesn't work )=
    Actually, it's used a great deal, especially by game programmers. It's not stressed in the learning phase too much, because the more formal if () code is more closely aligned with how people think.

    Code:
    #include <stdio.h>
    int main(void)
    {
    int variable;
    scanf("d%", &variable);
    variable ? printf("false\n") : printf("true\n");
    return 0;
    }
    Code:
    int n;
    scanf("%d", &n);
    printf("%n tire%c", ((n < 2) ?  c = ' ' : c = 's'));
    (Note: I don't use this much, and it's not tested).

    Arrays and pointers?
    OK i've decided these things are the reincarnation of the devil! These things are why I decided to make this list of questions...
    OK what I don't understand about them is:
    Pointers, why would you need / care about where something is located. I make a variable the computer makes room for the variable, I give it a value and the computer remembers it... So why after all that do we care where exactly at where it is located.
    And how do you use pointers )= I think I can make a 1 dimensional array fine. but pointers they are a mystery )= Of course so are 2 dimensional arrays.
    One more question on this it seems that with each dimension an array is given the more memory they require, at what point (how many dimensions) would be to much?
    Pointers are critical in getting maximum efficiency out of the computer's hardware. If you have trouble with them, just use them a little bit, and gradually, you'll get used to them. The larger and more complex your program, the more you need pointers.

    File scope?
    So theres global variables (entire program can use) local (Used within the function) external (from outside the program) and static (only within the program, can't be used outside it). I hope I got those right, my question in regards to these (I get local and global) is why would you need to declare static wouldn't it be better to just make sure your variables from other files (you intend to use / merge with this one) have separate variable names, would that solve the problems you may have?
    Static variables address a critical shortcoming of having just local variables. It's great when you can "encapsulate" the variable to within just the function that needs it. That way there's no chance of another function messing with it.

    return?
    I understand why main() should have a return, but what about all other functions.
    Returns can show you that the program made it through execution of any function, properly, usually by returning zero. Also, the returned number may be part of a critical calculation:
    answer = 3.14159265358979 * radius_sqrd().

    Headers?
    Why can't I find them )= I would like to take a look at them but don't know where to do so...
    When headers are added to files, are they completely added if you wanted to use printf() by adding <stdio.h> would you add the entire thing or only what deals with print()?
    If I would like to make my own printf() is it possible by using only the 32 c keywords? *very important. I must know (= *
    They're in their own subdirectories. Your compiler's doc's should tell you where the default location is. (Obviously the compiler/linker knows where they are, after all. )

    Yes, printf is written in C, but it's not a simple function.

    Hexadecimal base/octal?
    My only question is why use them? They seem to only confuse things, I mean you can't read them as easy as you can with regular numbers or can you? OK... so why use them (=
    Hexadecimal is helpful since the computers hardware groups bytes (with 8 bits), into words, which make up things like char's, integers, floats, etc. Hexadecimal is handy for memory locations and masking, and all kinds of things like that. It's compatible with the computer's hardware, and pretty easy for humans, as well.

    C != graphics?
    So it seems that all c can do is simple printing to the terminal screen )= Is there any way to make a window or anything nice looking (=
    If I ever did want to add graphics to my programs would I have to learn c++
    On this note what is C not good for, what would you never make a program in with c?
    Windows was originally coded in C, so the answer is definitely yes. C is also very much a commercial program, however, and stays independent of just PC's or just certain types of display monitors. I believe it tries a little too hard, but understand why it's done.

    lvalue and rvalue?
    My compiler laughs at me and says I have an error with the above words...
    So my first question is whats the command to force my computer to throw itself out a window... (=
    These only deal with improperly using variables, putting values on wrong side etc. right?
    The L value has to be a variable that can receive a value. Constant variables would be an example of something that could not be an L variable.

    Parameter = Argument?
    What is the main difference between the two?
    Same thing - house warming gifts for the function.
    Recursion:
    So I can make a function call itself? That sounds very "interesting" so how would I do that and what would my intention be if I did?
    Some problems are very eloquently solved by doing a little part of it, and then having the whole function call itself, taking the new value it's found, as a parameter, and then using that number to get even closer on the next recursive call, etc. Read the Wiki encyclopedia entry on Quicksort for a good example of recursion.

    It's important to remember that ALL recursive functions can be replaced by a regular (iterative), loop construction, but the beauty of recursion, is that it's easy to program, small, and elegant.

    I appreciate any help/insight into the above questions.
    Thanks in advance for any help that you can give
    BTW my first checking of this I got 70 mispellings (= I tried to get rid of them to make it easier to understand my questions forgive me if I missed some )=
    -Raven'sWrath
    That should give you a start!

  8. #8
    Registered User
    Join Date
    May 2007
    Posts
    45
    Quote Originally Posted by laserlight View Post
    Abstractions leak, and in other times bitwise operations come in handy. That said, magic numbers, regardless of the base they are expressed in, are usually better off as named constants instead of magic numbers.
    Very nice article there (=, i'm going to have to reread it later when I'm fully awake. I'm not really sure what you mean when you are talking at this point "...are usually better off as named constants instead of magic numbers" though.

    Thanks again for your reply (=

  9. #9
    Registered User
    Join Date
    May 2007
    Posts
    45
    Quote Originally Posted by zombiezparadize View Post
    I will answer three of your questions now.

    It is not that the auto keyword cannot be used at all. It is recommended by your books and tutorials not to use the keyword as it is added by the compiler by default when you dont specify anything else.
    For example if you write
    int i = 10;
    By default it means auto int i=10;
    So you dont need to use "auto"
    Not that you cant use it.


    Algorithms!
    Well a program implements an algorithm in the language you write the program.
    An algorithm may essentially be thought of as the
    well defined steps to do a particular task.
    For example:
    If you want to buy a computer the steps would be:
    Step 1: Save enough money
    Step 2: Decide what configuration, brand etc you want to buy.
    Step 3: Go to a shop.
    Step 4: Get your computer.

    This forms an algorithm.
    It is actually the breakdown of the steps you want to take in order to perform a particular task.

    When you go out of the scope of a function the variables declared in the function do not retain
    their value.
    If you want them to retain the value then you may want to declare them globally which is not recommended for extensive usage or may be use the static keyword which again has limitations of its own.

    I will go through your other questions and reply later!
    Till them happy learning!
    Thanks, your insight really does help. (=

  10. #10
    Registered User
    Join Date
    May 2007
    Posts
    45

    Talking

    Quote Originally Posted by Adak View Post
    An algorithm is just the steps your program goes through, to do it's work. If your algorithm is wrong, no matter how well the rest of your program's output or performance might be, the program will not complete it's work, accurately.

    Think of the steps you go through to go to work or school in the morning: wake up, clean up, get dressed, grab a bit of breakfast, get in your car and drive to work. Each is a step that would contain several steps of it's own. Some could be left out, like breakfast, but waking up is an essential step in the algorithm. Not only do you have to wake up, but you have to wake up *first*, before you can get anything else done.


    Code:
    print("%d", variable");


    I don't think of an argument as modifying a function. I think of it as a little house warming gift, you're delivering to the function. The function must know how to respond to that gift, and since the eyesight ain't what it used to be, you tell it what kind of a housewarming gift it is that you've brought today. Flowers get dunked in a vase of water - but a CD would not!



    Remember that C didn't just arise out of thin air. It was based on 'B', but included other idea's as well. The idea of "auto" was found overwhelmingly useful and popular, and made the default. I believe this was done in the early prototype of the language.



    Code:
    main(){
    somefunction() {
    int variable = 0;
    repate:
    variable++
    }
    goto repeate;
    }
    The result would vary from compiler to compiler, and OS to OS, but it would not be something you could rely on. When they talk about "undefined behavior", that's pretty much a euphemism for "you're totally goofed!"




    The values differ in size, perhaps, but shouldn't differ in value when you declare a variable to be some value. Int i = 0, is still going to get i equal to zero, regardless.



    Actually, it's used a great deal, especially by game programmers. It's not stressed in the learning phase too much, because the more formal if () code is more closely aligned with how people think.

    Code:
    #include <stdio.h>
    int main(void)
    {
    int variable;
    scanf("d%", &variable);
    variable ? printf("false\n") : printf("true\n");
    return 0;
    }
    Code:
    int n;
    scanf("%d", &n);
    printf("%n tire%c", ((n < 2) ?  c = ' ' : c = 's'));
    (Note: I don't use this much, and it's not tested).



    Pointers are critical in getting maximum efficiency out of the computer's hardware. If you have trouble with them, just use them a little bit, and gradually, you'll get used to them. The larger and more complex your program, the more you need pointers.



    Static variables address a critical shortcoming of having just local variables. It's great when you can "encapsulate" the variable to within just the function that needs it. That way there's no chance of another function messing with it.



    Returns can show you that the program made it through execution of any function, properly, usually by returning zero. Also, the returned number may be part of a critical calculation:
    answer = 3.14159265358979 * radius_sqrd().



    They're in their own subdirectories. Your compiler's doc's should tell you where the default location is. (Obviously the compiler/linker knows where they are, after all. )

    Yes, printf is written in C, but it's not a simple function.


    Hexadecimal is helpful since the computers hardware groups bytes (with 8 bits), into words, which make up things like char's, integers, floats, etc. Hexadecimal is handy for memory locations and masking, and all kinds of things like that. It's compatible with the computer's hardware, and pretty easy for humans, as well.



    Windows was originally coded in C, so the answer is definitely yes. C is also very much a commercial program, however, and stays independent of just PC's or just certain types of display monitors. I believe it tries a little too hard, but understand why it's done.


    The L value has to be a variable that can receive a value. Constant variables would be an example of something that could not be an L variable.


    Same thing - house warming gifts for the function.

    Some problems are very eloquently solved by doing a little part of it, and then having the whole function call itself, taking the new value it's found, as a parameter, and then using that number to get even closer on the next recursive call, etc. Read the Wiki encyclopedia entry on Quicksort for a good example of recursion.

    It's important to remember that ALL recursive functions can be replaced by a regular (iterative), loop construction, but the beauty of recursion, is that it's easy to program, small, and elegant.



    That should give you a start!
    Very much apreciated you answered the rest of my questions (=

    Code:
    They're in their own subdirectories. Your compiler's doc's should tell you where the default location is. (Obviously the compiler/linker knows where they are, after all.  )
    
    Yes, printf is written in C, but it's not a simple function.
    Well as long as my compiler can find it (= Off to the man pages I go (=

    About the printf function by complex do you mean something that would not be able to be done by a begininer or something that would take quite a bit of time doing (or both (; )
    Also do you know if when I use printf() function and use the stdio libary, does the linker take everything from that file (the stdio.h) or only what it needs to use printf()?


    Thank you all who responded to my posts (= You have been very helpful

  11. #11
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    When you include stdio.h, the entire file is included as if it's written at that point in your source.

    I think you can technically include printf() yourself by declaring its prototype instead of including stdio.h, which I believe is:

    Code:
    int printf(const char *, ... );

  12. #12
    Registered User
    Join Date
    May 2007
    Posts
    45
    Quote Originally Posted by MacGyver View Post
    When you include stdio.h, the entire file is included as if it's written at that point in your source.

    You could technically include printf() yourself by declaring its prototype instead of including stdio.h, which I believe is:

    Code:
    int printf(const char *, ... );

    Ok so I could make so that the entire header is not inserted into my program thats good (= I'm not sure why I was wondering about this but I suppose one of my reasons was that it could shrink the programs I make down some. Now I must learn how to use that prototype thing above

    Thanks
    -Raven'sWrath

  13. #13
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    I wouldn't recommend doing that, even if your compiler supports it. There's a reason why the headers were written the way they were written. Headers are usually written in some O/S and compiler specific manner, and they might require extra dependencies of some sort.

  14. #14
    Registered User
    Join Date
    May 2007
    Posts
    45
    Quote Originally Posted by MacGyver View Post
    I wouldn't recommend doing that, even if your compiler supports it. There's a reason why the headers were written the way they were written. Headers are usually written in some O/S and compiler specific manner, and they might require extra dependencies of some sort.
    I see )= well if thats true than I shall wait until I understand the header files and what they contain before I start playing with them, but if in theory its possible I shall keep that in the back of my mind until I'm able to know something won't go wrong (=


    If anyone knows about creating the printf() or puts() function by only using the c's keywords (the 32 of them... I think 32 of them) if you have any advice or hints at how it would be done I would very much like to hear them (=

  15. #15
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    > Also do you know if when I use printf() function and use the stdio libary, does the linker take everything from that file (the stdio.h) or only what it needs to use printf()?

    The compiler dumps the whole thing in. It pretty much has to, considering that stdio has some interesting responsibilities. It opens up a few streams that you use all the time: stdin, stdout, and stderr. These streams and the API for other streams (FILE pointers and its interface) are basically all of <stdio.h> The compiler can't tell what you're not using right away, although you will be pleasantly surprised to find that after a proper build you should only see generated assembly for what you used. Go with "it doesn't matter how big the code is" on this one. Real programmers do not mind long compile times.

    About the return values in functions, there is no reason to think that all functions need return values. It usually becomes apparent whether you will return a value or not while your thinking about an algorithm or how a function should fit in your program's design. Return values have two basic purposes: to hand you something you need (a calculation perhaps) or error handling capability, like that in main. main is little special, though. Its return value is something the OS depends on quite a bit because their may be more to do than ending the process quietly. And what if during one of your programs you wanted to communicate with another process? main's return value becomes the difference between running the next program or not running it.



    Bleh. That took forever to write properly. Hopefully I helped.

    Generally, rewriting printf is a waste of your time btw. You could hack it, but the type checking would never be as strict as the standard one (without fundamentally changing how it's called anyway) which is pretty much useless to you.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 06:59 AM
  2. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  3. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 11:36 AM
  4. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 06:40 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21