C/C++ Beginner's Guide and Post Basic Questions here

RBX

In the zone
Re: Post your C/C++ Programs Here

'A', I think, is evaluated differently in C and C++

I use TurboC compiler, it appends cpp extension by default.

So, when using cpp (C++) : printf("%d",sizeof('A')); resulted in 1 (char)
but when I switched to .c extension, the result changed to 2.
 
OP
Liverpool_fan

Liverpool_fan

Sami Hyypiä, LFC legend
Re: Post your C/C++ Programs Here

^ That's because in C, the character literal like 'a', etc. are of type int (4 byte usually) NOT char.
In C++, it's of type char (1 byte).

Apparently you are using a 16bit compiler (Turbo C++. eww leave that crap and use a proper compiler), so you are getting 2 byte as the size of integer.
 

RBX

In the zone
Re: Post your C/C++ Programs Here

^ That's because in C, the character literal like 'a', etc. are of type int (4 byte usually) NOT char.
In C++, it's of type char (1 byte).
That explains. I'm curious why there's such a difference in both languages ? Is C++ not supposed to be compatible with C ?

Turbo C++. eww leave that crap and use a proper compiler
You know what, I just switched ;)
to gcc
 
OP
Liverpool_fan

Liverpool_fan

Sami Hyypiä, LFC legend
Re: Post your C/C++ Programs Here

That explains. I'm curious why there's such a difference in both languages ? Is C++ not supposed to be compatible with C ?
I think C has that due to historical reasons. There was a link explaining that, but I can't seem to find it now.
Regarding the second point, C++ should be considered to be a very different language to C, even though synatically they are similar but the approach of programming is very different.
 

RBX

In the zone
On the Compiler thing. I downloaded and installed gcc 4.6.0.

Now, I'm confused over which of the available tools should I be using.

I used gcc for compiling .c and .cpp files and it seems they both worked as intended.
I then tried g++ and compiled both .c and .cpp files and it seems they both were treated as C++ programs.

So, is gcc an extension dependent compiler and g++ a C++ specific ? And, I can use only 'gcc', keeping the extensions correct ?
 
OP
Liverpool_fan

Liverpool_fan

Sami Hyypiä, LFC legend
What is the difference between g++ and gcc? - Stack Overflow
c++ - Difference between CC, gcc and g++? - Stack Overflow
Performance difference between gcc and g++ for C program - Stack Overflow
What's the difference between gcc and g++/gcc-c++? - Stack Overflow

I think it's pretty clear use gcc for C programs. While you can use gcc for C++ with -lstdc++ flag as well since GCC = Gnu Compiler's collection and it calls the appropriate compiler according to file extension, however g++ will directly call the C++ compiler, so your source will be compiled as a C++ program.
 

RBX

In the zone
The main differences:

gcc will compile: *.c/*.cpp files as C and C++ respectively.
g++ will compile: *.c/*.cpp files but they will all be treated as C++ files.

The less voted answer says what I want but gcc's unmentioned inability to pull c++ files suggest that I should use g++ for C++ and gcc for C.
 
OP
Liverpool_fan

Liverpool_fan

Sami Hyypiä, LFC legend
The less voted answer says what I want but gcc's unmentioned inability to pull c++ files suggest that I should use g++ for C++ and gcc for C.

Code:
gcc -lstdc++ abc.cpp -o a.exe

gcc can compile C++ code, with right extension and the flag -lstdc++, since with that flag it links the standard C++ libraries. g++ uses that by default, so less typing. So stick with g++.
 
OP
Liverpool_fan

Liverpool_fan

Sami Hyypiä, LFC legend
There's no black and white answers for using an IDE. It depends on the learner. However for absolute beginners, it's strongly advised to begin coding in a text editor, and step by step compile and execute rather than simply jump to an IDE. After the basics are clear, IDEs can be great.
 

achuthan1988

Broken In
Starting tutions for cbse XII (C++) HELP!

I am planning to start taking C++ tutions for CBSE class XII students.The boys who have approached me told me that they are using turbo C++ as the compiler.They are also using Sumitha Arora's book as reference.

1)I need a link to download the turbo C++ compiler
2) I also need a good reference book for C++ at class XII level .
 

nims11

BIOS Terminator
1. Free File Hosting & Video Downloads, Free File Sharing, Online Friends Network - Ziddu
2. sumita arora should be enough for class XII. however, you may want keep C++ : complete reference or any other good book with you.
 

Vyom

The Power of x480
Staff member
Admin
@achuthan1988: I am sorry to say this, but if you going to use Turbo C++ as the compiler, as well as the book by Sumita Arora as the book, you would be the worst teacher for any student.
I strongly recommend you to read the first post of this thread.

And use, GCC as the compiler, and Thinking in C++ as the reference book.
 

nims11

BIOS Terminator
And use, GCC as the compiler, and Thinking in C++ as the reference book.

Your comment is 100% valid if the tuition was for general students/people who wanted to Learn Programming.

he teaching class XII CBSE students! for them, marks is a higher priority (sad but true). no doubt every programmer should be using the current standards but students are required to use the junk compiler at schools and practicals.
as For THINKING IN C++, it is an excellent book and i am currently reading it but i doubt if most of the topics in the book will be of much use for them.

I might sound quite stupid but the above statement was keeping the current education system and student mentality in mind. if the achutan1988 starts teaching class XII students (who have joined his tuitions for securing good marks in boards) under GCC, he will only lose them.

Anyway, from my experience, it ain't a big deal using gcc and newer standards for regular use and using the junk stuffs for school purpose. i am doing the same thing in college right now.
 
OP
Liverpool_fan

Liverpool_fan

Sami Hyypiä, LFC legend
Re: Starting tutions for cbse XII (C++) HELP!

I am planning to start taking C++ tutions for CBSE class XII students.The boys who have approached me told me that they are using turbo C++ as the compiler.They are also using Sumitha Arora's book as reference.

1)I need a link to download the turbo C++ compiler
2) I also need a good reference book for C++ at class XII level .

1. The link to You-know-what compiler cannot be provided here, since most links are unlicensed and therefore illegal. You may however get the download from "antiquated downloads" from Borland Website.
2. For a good reference book to You-know-what compiler, check out "Object Oriented Programming in Turbo C++ by Robert Lafore", the old edition.

Make sure you guide students well enough, and make them aware that what they are learning are of no use apart from getting them marks in the Class XII board examinations. Also at least you as a teacher should be able to use modern compiler, and with modern concepts, if you don't want to be ever tripped or humiliated by a slightly smart student.

is there a standalone c++ compiler for windows 7 64 bit?

Check out Code::blocks. Downloads
Make sure you download the version with bundled MinGW.

And from your thread, I can see you come from a You-know-what Compiler background, keep note you are in for a bit of a shock.
If it's school/college stuff you want to manage, dual work with MinGW/Code::blocks and You-know-what compiler running under DOSBOX.
 

Neuron

Electronic.
Actually running it under DOSBOX isn't a good idea.Some programs give incorrect outputs or may malfunction under DOSBOX.
 
Top Bottom