Some questions

This is a discussion on Some questions within the C++ Programming forums, part of the General Programming Boards category; Hello, I'm a complete beginner at C++, and I wanted to ask some n00b questions. I couldn't find/understand answers anywhere ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Latvia
    Posts
    102

    Post Some questions

    Hello, I'm a complete beginner at C++, and I wanted to ask some n00b questions. I couldn't find/understand answers anywhere on the web, nor on these forums...so, here they are:

    1. What's the differrence between:
    Code:
    char a;
    and
    Code:
    char* a
    I know, it's a pointer, but why do people use char *a more than just 'char a'? What's the purpose of it? How can I use it and find it useful?

    2. How to use volatile?

    3.
    Code:
    *pVal = atof(szVolAdjust);
    Again, why * ?

    4. Is network programming easy?

    5. How to get the value of getch() into a variable?

    6.
    Code:
    static void cap_set_pg()
    What's the use of static here?

    7. Why can't dev-c++ compile most of those complex programs?

    8.
    Code:
    struct b{
    int g;
    char *jam;
    char* unjam;
    }
    and
    Code:
    typedef struct{
    int g;
    char *jam;
    char* unjam;
    }
    What's the use of typedef here?

    9. How to make the program quit if(quit=1) ?

    10. How to make my program to open another program? (For example, a CD autorun program shows welcome message, and then opens the folder of CD contents)

    11. Program:
    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    int main()
    {
    ofstream read("file.txt");
    int count;
    int count2;
    cout<<count<<"\n"<<count2;
    cin.get();
    }
    file.txt:
    Code:
    count1=4
    count=8
    How to make the program assign the values from file.txt into variables count and count1?

    12. How to access a structure from a class?
    Code:
    class fragile
    {
    public:
    fragile();
    ~fragile();
    struct tnt
    {
    int h;
    };
    };
    
    int main()
    {
    fragile fr;
    fr.tnt dyna;
    fr.dyna.h=6; //doesnt work
    13. How to get the cout<<'ed text into a variable?

    14. Whats the use of '?' in C++?

    15. What is union REGS?

    16. What is
    Code:
    extern int  *a;
    ?

    Sorry for such stupid questions, I know you won't want to waste your time to answer them, but please understand me, I want to strenghten my C++ knowledge and help others too.
    Last edited by Overlord; 06-30-2006 at 10:25 AM. Reason: update

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    Is network programming easy?
    Is programming easy?

    Why can't dev-c++ compile most of those complex programs?
    The programs you speak of may not be portable, or you may not have the required dependencies (like libraries).

    Instead of asking random and disparate questions here, I suggest that you take a look at the C++ Book Recommendations. Accelerated C++ is a good read to get you started on C++ programming, especially since it appears that you already have a compiler and have tried your hand at some C++ programs.
    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

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    903
    1. Most often, people will use char* for dynamic memory allocation. This means that you can allocate memory with runtime information.

    2. Can't recall.

    3. atof() turns a string into a floating-point number. I assume that pVal is a pointer to a float, most probably in a function; therefore, * dereferences the point which means that you access that value pointed by pVal and assigns it to the result of atof().

    4. It highly depends on what you're doing.

    6. It means that you don't need to instanciate an object of the class to use this function. You can use the following syntax: myClass::myStaticFunction().

    7. Dev-C++ can compile any C++ program if you set it properly.

    8. Your second code makes no sense to me.
    Code:
    typedef struct tagWhatever {
        /* ... */
    } Whatever;
    This is what you'll see often. This is because in C when you instanciated objects of a struct or a class, you had to put the struct/class keyword in front of it like this: struct tagWhatever myObject. However, with this technique, you are telling the compiler that you want to typedef a struct tagWhatever to Whatever which means that you don't need the struct/class keyword anymore.

    9.
    Code:
    bool quit = 0;
    while(!quit) {
        /* ... */
    }
    12. This is because you haven't created an object of tnt.

    14. It's a conditional operator.

    Code:
    int min = a > b ? b : a;
    
    // if a is greater than be, return b, else return a

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,403
    char a is a variable named a of type char.
    char* a is a variable named a of type pointer to char.
    Read about pointers on the tutorials and C-Style strings. The second line creates a C-Style string named a.

    2.
    Volatile is not your friend. Well, it can be your friend, but it's one of those friends you cannot trust... just use (ouch!). The problem is that it is inherently specific to the compiler you are using. Volatile tells the compiler not to optimize any variable declared with this qualifier. It asks the compiler so, because volatile variables are variables that can be changed at run-time by processes outside the compiler control. A typical example is a variable that gets changed automatically by the system clock. Forget about these for now. You may need them later on. Much later on. So you are safe.

    3.
    *pVal = atof(szVolAdjust);
    The value returned by the atof() function is being copied to the object being pointed by pval. Again read about pointers.

    4.
    Network programming is only easy after you know how to do it and have been doing it for some time. Even so, it may be an hell lot of hard, depending on what one wants to do. So, in the best tradition of "How to approach learning", network programming is hard.

    5.
    Read about getch(). It's all there.

    6.
    A static member function can only access static member data. It cannot access private or public data. Because of this it has one ability and a lot of handicaps. The one ability is important though. It can be called even before any object of that class has been instatiated. Static member functions are usually used to initialize or alter the state of the class static members.

    7.
    Why can't dev-c++ compile what? Dev-C++ can compile about anything that follows C++ rules as long as the needed libraries are installed.

    8.
    No use on C++ programs. Mandatory on C programs. It exists on C++ for backward compatibility with C

    9.
    Depends on where the test is being done in your code.

    10.
    There's a tutorial on that. Read the tutorials.

    11.
    read the tutorials.

    12.
    Code:
    struct tnt
    {
    int h;
    };
    
    class fragile
    {
    public:
    fragile();
    ~fragile();
    tnt blah;
    };
    
    
    int main() {
    
    fragile fr;
    fr.blah.h = 12;
    
    }
    13.
    Declare the variable, assign to it what you want to cout, and then cout the variable.

    14.
    It's a compile-time error. Unless you want to explain exactly where you saw it.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

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, 08: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

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