I am newbie in C++ programming.
I am learnging programming in C++. I have read through some websites and books. I thought out the following questions. Please help!
I want to use MS visual C++ to program.
1/ What is the difference between .c and .cpp?
2/ Does the c codes got from the internet work properly in MSVC++?
3/ I saw two different types of pointers: ^ or *. What are the differences?
Learning troubles about C++?
1). .c is the extension for C source code files while .cpp is the extension for C++ source code files. The main difference between C and C++ is that C isn't object oriented while C++ is.
2). Not all of them work on Microsoft Visual C++. If you installed the latest 2005 or 2003 edition, the syntax for it is a bit different (because it only compiles on .NET platform).
3). There are two types of pointers in C++:
- the reference operator (%26amp;)
- the dereference operator (*)
The address that locates a variable within memory is a reference to that variable. For example:
int* x;
int y=10;
x=%26amp;y; // x will pointer the memory location where y is located.
Using a pointer you can directly access the value stored in the variable which it points to. To do this, you simply have to precede the pointer's identifier with an asterisk (*), which acts as dereference operator and that can be literally translated to "value pointed by".
int *p1,*p2;
*p1=10; //value pointed by p1 is 10
*p2=*p1; //p2 and p2 point the same value
p2=p1; //the pointers are being copied
Hope it helps.. If you have any questions please e-mail me
Reply:1) .c is for C language, .cpp is for C++ language, it's just a file extension, there's nothing preventing you from putting C++ compatible code in a .c file and compiling it using a C++ compiler.
2) Usually, code from the internet might need to be modified slightly to work correctly. Sometimes function names change, or OS version changes will cause code to need to be modified to work.
3) * is the standard C / C++ pointer operator. In .net, you can do managed C++ which uses the ^ pointer operator. By default in languages like C# and VB.net, all class instances are actually pointers using the managed pointer operator (^). In traditional C++, you will never use the managed pointer operator because it is .net and Microsoft specific.
Reply:1
.c for c files
.cpp for c++ files
2
you must not find anything wrong, it will work properly
3
i think both are the same
Reply:I think there is a code in c for dos that don't run in MSVC++
For me it's very hard to code on MSVC++ because if you forgot one code it will display many error which sometimes confused you.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment