Click to See Complete Forum and Search --> : Free C tutorials...
Bigjakkstaffa
08-23-2002, 03:24 PM
Hi all, im starting to use C language at college in a few ekksand am thinking about trying to get an insight into the language before i start, anyone one know of any free tutorials or resources availiable on the internet?
--Cheers
--Jakk:t
Quandary
08-23-2002, 04:05 PM
C or C++?
How basic of a grounding do you you want?
I can post a short lecture on C++; for anything in-depth, you'll have to find a book at your local library.
Bigjakkstaffa
08-23-2002, 04:53 PM
We'll be starting with C id have thought, and only the basics as of yet, as i this is the first time any of us will be using the language, C++ stuff might be useful too though - id love to have a look at whatever you can give me - cheers...
--Jakk:t
Quandary
08-23-2002, 06:52 PM
Okay, lets start with the basics.
All statement lines end with a semicolon. Just the way it is.
Variables store data (duh). They are defined as <type> <declarator>. Here are the basic types for C++:
char - 1 byte
short - 2 bytes (word)
int - 4 bytes (dword)
long - also 4 bytes
float - single-precision floating point var
double - double-precision floating point var
bool (C++ only; BOOL in c, which is actually just a typedefed int)
char data is usually charachter data (char -> character. no brainer.)
Strings are an array of chars, and an array is just a whole bunch of subsequent data peices in memory, but that is actually a more advanced topic. (a loooong lecture on pointers and ****.)
So, if I go
int foo;
I now have a variable, foo, that is an integer (double word).
Standard operators include (deeep breath :p)
= assignment; read as gets, so a = b reads a gets b.
== equal to (equal two :p)
!= not equal to
< less than
> greater than
<= less-than equal to
>= greater than equal to
|| logical OR
&& logical AND
! logical NOT
& bitwise AND (or 'address of')
| bitwise OR
^ bitwise XOR
~ bitwise NOT
- subtract
* multiply (or 'pointer to' or 'derefrence')
/ divide
+ add
++ increment
-- deincrement
and more.
Simple control structures include:
if(bool expression)
{
statements
}
else - else is optional. another if after the else will make an else-if statement.
{
statements
}
while(bool expression)
{
statements
}
do
{
statements
}while(bool expression);
for(starting statement; bool expression; per-loop statement)
{
statements
}
which (except for for) are all pretty self-explanitory. There are other control statements (like case) that are more advanced.
For a program to compile, you need to make a function called main. To do that, you just have to write in the following:
void main()
{
(programming statements go here)
}
and then code inside of the braces.
if you do this at the top of the file:
#include <stdio.h>
You include a header file that gives you access to a printing function. To disply things on the screen, go:
printf("Your message here");
If you use a %d inside of the quotes, you can print out a numeric value, a %c prints a char. So...
int foo = 5;
char bob = 'a';
printf("%d %c", foo, bob);
would print out
5 a
There are your basics!
If you want more, just IM :p
- Q
Bigjakkstaffa
08-23-2002, 07:11 PM
Cheers, coming up bed time now, so ive just popped that into a word file for reading tomorrow or another time - i'll IM you if and when i want more - tnx :)
--Jakk:t
rick42
08-24-2002, 03:56 AM
Come on you guys. Don't you know that C is self documenting ;)
Actually it is like any other language,
- watch your indentation
- keep mariables meaningfull, including temp vars (use iix, not i)
- keep functions short
- use brackets for those not too obvious relationships (eg. is ++iix* the same as ++(iix*) or (++iix)* ?)
If you're not sure, make a micro pgm, and test it.
:D
ps: try cc -E src, to test your macros and includes.
SysOpt.com
Copyright Internet.com Inc. All Rights Reserved.