basic questions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nemisis
    New Member
    • May 2007
    • 61

    basic questions

    Hi, I would like to know some answers of some basic questions. I am working on linux

    1)What are the advantages/disadvantages of commands at the console promp compared to using GUI programs?

    2) When does the header file get compiled?

    3)What is the output of the compilation stage?

    4) what does a cin.ignore() command do?

    5)In general what is the role of “const”
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by nemisis
    Hi, I would like to know some answers of some basic questions. I am working on linux

    1)What are the advantages/disadvantages of commands at the console promp compared to using GUI programs?

    2) When does the header file get compiled?

    3)What is the output of the compilation stage?

    4) what does a cin.ignore() command do?

    5)In general what is the role of “const”

    1)What are the advantages/disadvantages of commands at the console promp compared to using GUI programs?
    It is easier to come up with console application in C++ compared to GUI.
    If you want to go for GUI its better to use java etc...

    2) When does the header file get compiled?
    Header gets expanded inside the C/C++ file during preprocessing and so it gets compiled along with the source file

    3)What is the output of the compilation stage?
    It produces the.o or the object file

    Raghuram

    Comment

    • mmk
      New Member
      • Oct 2006
      • 19

      #3
      Originally posted by nemisis
      Hi, I would like to know some answers of some basic questions. I am working on linux

      1)What are the advantages/disadvantages of commands at the console promp compared to using GUI programs?

      2) When does the header file get compiled?

      3)What is the output of the compilation stage?

      4) what does a cin.ignore() command do?

      5)In general what is the role of “const”

      4) what does a cin.ignore() command do?

      cin.Ignore function will ignore, consume or pass by a character you specify. Theres two arguments to the ignore function.

      Heres the syntax: cin.ignore(num, delimChar); --You can use it with cin or your file object name .

      So if we said: cin.ignore(555, '#'); The ignore function stops reading and discarding characters once its consumed the num (555) of characters or has reached the delimChar (#)


      5)In general what is the role of “const”

      The const modifier has many shades of meaning, depending on context. const makes it illegal to modify the variable after its initialization. For example:
      --------------------------------------------------------------------
      int x = 4; // a normal variable that can be modified
      x = 10; // legal

      const int x = 2; // const var can be initialized, not modified thereafter
      x = 10; // error - cannot modify const variable
      --------------------------------------------------------------------
      Thus, const can replace the use of the #define to give names to manifest constants. Since preprocessor macros don't provide strong compile-time type checking, it is better to use const than #define. Moreover, some debugging environments will display the symbol which corresponds to a const value, but for #define constants, they will only display the value.

      Comment

      • nemisis
        New Member
        • May 2007
        • 61

        #4
        Thanks for the above answers, here a bit more on which i need to undertsand...


        What is the purpose of #includ(ing) a class header within the class implementation file?

        In general what are the advantages and costs of using vectors rather than arrays

        In what cases would you use a vector? When would you use array?

        Why is a function parameter, or a function return value never const when they are values (not references or pointers)?

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Originally posted by nemisis
          What is the purpose of #includ(ing) a class header within the class implementation file?
          I suggest you find out by compiling a class implementation file without the class header included.

          Originally posted by nemisis
          In general what are the advantages and costs of using vectors rather than arrays
          vectors are variable size and have a well defined interface. The is very little overhead in using a vector instead of an array.

          Originally posted by nemisis
          In what cases would you use a vector? When would you use array?
          In general always use a vector. The only case I would use an array would be for a short lived (local) and small variable in a function that was going to hold a known size of data.

          Originally posted by nemisis
          Why is a function parameter, or a function return value never const when they are values (not references or pointers)?
          Appart from references C++ passes by value, this means that the function can not change the value of the variable in the calling code only its local copy so there is no need for the parameter to be const. When passing by reference or using a pointer the calling function can change data external to itself (data in the calling function maybe or other data) via the pointer or reference. Declaring a pointer or reference parameter const declares that the function called is unable to change the data referenced/pointed to.

          Comment

          Working...