Great resources for beginning C programming
Ranked #81,010 in Computers & Electronics, #1,246,052 overall
Short intro to beginning C programming
Starting C programming is tough!
As with any other language, you really need a good portion of links, books, articles and tutorials.
Here I will attempt to share the references I have used, when I first started programming with C .
In my early days, I started with PHP, which has proven to be a VERY good starting point.
Especially if you get the Object Oriented way of doing things.
As with any other language, you really need a good portion of links, books, articles and tutorials.
Here I will attempt to share the references I have used, when I first started programming with C .
In my early days, I started with PHP, which has proven to be a VERY good starting point.
Especially if you get the Object Oriented way of doing things.
A short introduction to C++
To start out, lets create the simple "Hello World" example:
1: #include
2:
3: int main()
4: {
5: std::cout << "Hello World!" << std::endl;
6: return 0;
7: }
Breakdown:
Line 1: #include
#include will include a C++ library - in this case the iostream library
The iostream library is used to "get" and "send" streams of data - usually text strings.
Line 3: int main()
"int" is a desription of what type of value, the function will return.
main() is the function that will be called as the first thing, when the program is run.
Line 4: {
This marks the start of a block of code...
In this case, it starts the content of the main() function.
Line 5: std::cout << "Hello World!" << std::endl;
First of: cout is a way of printing something to the standard output - i.e. your shell.
endl is the same as this: "\n"
A newline character.
std:: is refering to would is called the standard namespace...
Namespaces is used in C++ to create distinct areas for you classes, functions, etc.
An example: std::my_function() is completely different from myns::my_function().
Don't worry about this at first...
To make things easier, you could remove the std:: declarations from line 5 and add this to line 2: using namespace std;
So that these lines looks like this:
2: using namespace std;
...
5: cout << "Hello World!" << endl;
Line 6: return 0;
Remember that line 6 created the function main, that will return an int (integer or a positive number)?
Well this is where we actually return an integer... in this case 0, which means everything went alright.
Line 7: closes the block of code defined as the function main()
That's it! Really! ;-)
Save the code in a file called helloworld.cpp - or what ever you like, as long as you remember to use .cpp as the extension.
Compilation... Well... There is so many options, when it comes to choice of a C++ compiler...
Mostly it depends on operating system... I will NOT get into C++ development specific to the Windows platform, as I am only used to UNIX like operating systems (yes that includes the Mac)...
Well the most popular compiler on Linux / BSD platforms are the gnu c++ compiler.
You can check if you have it, by running this command in your shell:
g++ -v
This should tell you all kinds of things, but look for a line similar to this:
gcc version 4.0.1
This tells you that the compiler is installed, and what version is installed.
If you haven't got the compiler... get it... on debian linux you can run the following command:
sudo apt-get install g++
assuming you have root access, that is...
Well... to the actual compilation...
Run this command in your shell:
g++ helloworld.cpp -o helloworld
This will create a program called helloworld, as this is what you asked for (-o helloworld)
Now run the program with:
./helloworld
And you should see this:
Hello World!
Well... This is it for now!
Leave a comment, if you have any questions!
I hope you learned something and enjoyed the site!
Best regards
Dan Larsen
1: #include
2:
3: int main()
4: {
5: std::cout << "Hello World!" << std::endl;
6: return 0;
7: }
Breakdown:
Line 1: #include
#include will include a C++ library - in this case the iostream library
The iostream library is used to "get" and "send" streams of data - usually text strings.
Line 3: int main()
"int" is a desription of what type of value, the function will return.
main() is the function that will be called as the first thing, when the program is run.
Line 4: {
This marks the start of a block of code...
In this case, it starts the content of the main() function.
Line 5: std::cout << "Hello World!" << std::endl;
First of: cout is a way of printing something to the standard output - i.e. your shell.
endl is the same as this: "\n"
A newline character.
std:: is refering to would is called the standard namespace...
Namespaces is used in C++ to create distinct areas for you classes, functions, etc.
An example: std::my_function() is completely different from myns::my_function().
Don't worry about this at first...
To make things easier, you could remove the std:: declarations from line 5 and add this to line 2: using namespace std;
So that these lines looks like this:
2: using namespace std;
...
5: cout << "Hello World!" << endl;
Line 6: return 0;
Remember that line 6 created the function main, that will return an int (integer or a positive number)?
Well this is where we actually return an integer... in this case 0, which means everything went alright.
Line 7: closes the block of code defined as the function main()
That's it! Really! ;-)
Save the code in a file called helloworld.cpp - or what ever you like, as long as you remember to use .cpp as the extension.
Compilation... Well... There is so many options, when it comes to choice of a C++ compiler...
Mostly it depends on operating system... I will NOT get into C++ development specific to the Windows platform, as I am only used to UNIX like operating systems (yes that includes the Mac)...
Well the most popular compiler on Linux / BSD platforms are the gnu c++ compiler.
You can check if you have it, by running this command in your shell:
g++ -v
This should tell you all kinds of things, but look for a line similar to this:
gcc version 4.0.1
This tells you that the compiler is installed, and what version is installed.
If you haven't got the compiler... get it... on debian linux you can run the following command:
sudo apt-get install g++
assuming you have root access, that is...
Well... to the actual compilation...
Run this command in your shell:
g++ helloworld.cpp -o helloworld
This will create a program called helloworld, as this is what you asked for (-o helloworld)
Now run the program with:
./helloworld
And you should see this:
Hello World!
Well... This is it for now!
Leave a comment, if you have any questions!
I hope you learned something and enjoyed the site!
Best regards
Dan Larsen
Here is a couple of links to follow:
- C++ Language Tutorial (my favorite)
- C++ Language Tutorial, C++ Documentation
- Stroustrup: C++ Style and Technique FAQ
- A page with FAQs from Bjarne Stroustrup himself... You know... The designer of the language ;-)
- C++ tutorial for C users
- C++ tutorial for C users
This text shows and highlights features and basic principles of C++.
It is aimed at experienced C users who wish to learn C++.
It can also be of interest to beginning C++ users to remind them of facets of
the language. - C++ For C Programmers
- C++ For C Programmers
Part of the CIT Training Program at NIH
Amazon
This book should be on every C++ programmers shelf!
It is written by Bjarne Stroustrup, who is the designer of the C++ programming language!
If you don't have it... get it!
It is written by Bjarne Stroustrup, who is the designer of the C++ programming language!
If you don't have it... get it!
YouTube vids
This is a bit more fun "first C++ program", with some explanations of the code.
I should have covered compilation elsewhere on this "lense" ;-)
I should have covered compilation elsewhere on this "lense" ;-)
Google Blog Search
- Turning DNA into a hard drive
- We automated computer design so that human beings didn't have to do it manually. Somebody invested in some programming languages along the way. C++ didn't get discovered under a rock and Java wasn't grown on a tree. You have to work on tools.
- Why should I have written ZeroMQ in C, not C++
- Just to be clear from the very beginning: This is not going to be a Torvalds-ish rant agains C++ from the point of view of die-hard C programmer. I've been using C++ whole my professional career and it's still my language of choice when doing most ...
- In-depth: Functional programming in C++
- I do believe that there is real value in pursuing functional programming, but it would be irresponsible to exhort everyone to abandon their C++ compilers and start coding in Lisp, Haskell, or, to be blunt, any other fringe language.
- Answered by the Experts: Heterogeneous and GPU Compute with AMD's Manju Hegde
- GPU Compute C++ support: This makes heterogeneous compute access a lot of the programming constructs that only CPU programmers can access today 2. HSA Memory Management Unit: This allows all system memory is accessible by both CPU or GPU, depending on ...
by morphar
I am what most people would call a nerd... Well... I am proud of it!
Being a nerd, means that you love what you are doing, and that you are good at it...
more »
- 0 featured lenses
- Winner of 2 trophies!
- Top lens »
Feeling creative?
Create a Lens!