Welcome Guest ( Log In | Register )



2 Pages V   1 2 >  
Reply to this topicStart new topic
> [tutorial] Basics Of C Programming - Part 1
dhanesh
post Jul 26 2006, 05:32 PM
Post #1


Binary Geek
Group Icon

Group: Members
Posts: 444
Joined: 4-November 05
From: The Digital Arena
Member No.: 9,440



Well, I was going through a few posts on C / C++ on asta .. and found a very less C related subjects. I went through the entire tutorial of mastercomputers >>HERE<< .. It was a nice tutorial for guys who have a little knowledge of programming basics and want to go into hardcore programming. Since there was no Basic overview of what C was, i thought of writing one smile.gif. I wil make shure that what i write will be 100% accurate, but its human to error so please correct me if i am wrong. Lets start off ...

Introduction to C

Topics Covered :
  • History of C
  • Characteristics / Features
  • Structure of a C Program
  • Desirable Program Characteristics
  • C Character Set
  • Identifiers & Keyword
  • Constants
  • Expression
  • Statements
  • Symbolic Constants

History of C

  • This language was developed by Dennis Ritchie in 1970 at t he Bell Lab.
  • It was official released only in 1978.
  • 1980s it evolved as a most effective language because of its desirable features.
  • It was instantly adapted even for developing commercial applications
  • Many Software products which were written in other languages we rewritten in C for its efficiency and portability.
  • With the advent of C many C compilers and interpreters were written and released into the market
  • They differed from the original C language this lead to the lack of portability that the language promised to provide
  • AT this point ANSI developed certain standardized norms for the C language and today all C compilers adhere to this ANSI Standard.
Characteristics / Features
  • Ability to write very concise source codes in spite of having a large number of operators.
  • It has a small instruction set
  • It has library functions that enhance the basic instruction.
  • The features and capabilities can be easily extended b the users as it encourages users to write additional library functions
  • C Compliers are compact and generate smaller and highly efficient object code compared to other high level languages.
  • C Programs are highly portable as its library set avoids all to computer dependent features.
  • C Compliers are compact and generate smaller and highly efficient object code compared to other high level languages.
  • C Programs are highly portable as its library set avoids all to computer dependent features.
Structure of a C Program

CODE
/* Simple Program to Add 2 Values*/            /* Title*/[/color]
[color="#996633"]# Include<stdio.h>                        /*Library File Access*/
main()                                          /* Function Heading*/
{                                                  /* Start of the Function*/
    int n1,n2,sum;                          /* Variable Declaration*/
    printf(“Enter First Value : “);        /* Output Statement */
   scanf(“%d “,&n1);                       /* Input Statement */
   printf(“Enter Second Value : “);    /* Output Statement */
   scanf(“%d “,&n2);                       /* Input Statement */
   sum=n1+n2;                              /* Assignment Statement*/
   printf(“Sum is : %d “,sum);          /* Output Statement */
}                                                  /* End of function Main*/



Desirable Program Characteristics
  • Integrity
  • Clarity
  • Simplicity
  • Efficiency
  • Modularity
  • Generality
C Character Set

  • Uppercase A - Z
  • Lowercase a - z
  • Digits 0 – 9
  • Special characters
These are used as building blocks to form basic program elements


Identifiers & Keyword

Names given to basic program elements such as variables, Functions etc. Certain norms they have to follow:
  • Name can be of alphanumeric type
  • But should start with a alphabet
  • It is case sensitive
  • Keywords are reserved words that have a predefined function in C
  • Keywords can be used only for the purpose they are intended for
  • Keywords Cannot be used as program defined identifiers
Constants

They contain a specific value.
Four types :

Integer & Floating Point Constants

They are normally reffered to as numeric constants
Follow certain norms:
  • Commas and blanks cannot be included within the constant
  • Can be preceded with a – sign if required
  • Value should be within the specified range .
Integer Constants

These are nothing but integer valued numbers.
Can be written in 3 number systems :
  • Decimal Integer Constant ( Base 10)
Contains digits between the set 0 to 9
If consists of more than one digit should start with a value other than zero.
  • Octal Integer Constant ( Base 8)
Contains digits between 0 to 7
First digit must be a zero
  • Hexa Integer Constant (Base 16)
Begins with a either 0x or 0X followed by digits
Set could contain 0 to 9 and a – f (Lower or Uppercase)

Floating Point Constants

  • This is a base 10 number having a decimal value or a exponent.
  • In case of representation of a exponent is similar to the scientific notation except that 10 is replaced by E or e
Eg : 10.8X 10 -3 : 10.8E-3 or 10.8e-3

Character Constants

  • Single character enclosed within Single apostrophes
  • All character constants have integer values that determine them in the character set .
  • Character set standardized by the ASCII here each character is numerically encoded with its own unoaque 7 bit coding
Combination of special characters that are used for special purpose .
Always started off with a \ .
Eg \n, \t etc.

String Constant

  • Consecutive sequence of characters within double quotations.
  • Uses \0 ( Null) string terminator at the end of the string.
Expression

  • Represents a single data item which could be a number or character .
  • It could be single entity as a variable function or constant or a combination of entities connected by a operator.
Eg. C=a+b;


Statement

This Causes the computer to perform a action
Types:
  • Expression Statement
  • Compound Statement
  • Control Statements.


Symbolic Constant

  • Name that substitutes with a sequence of characters.
  • These sequence of characters could represent a numeric , character or a string constant.
  • They have to be defined at the beginning of the program
  • Done by using the keyword : # define pi 3.141
Well i hope this helped a few new commers to the programming field, I am a little bored and tired now .. but will finish the next topic of Operators & Expressions in C , in the next tutorial. Suggestions and Critisizm are welcome smile.gif ..

Regards
Dhanesh.
Go to the top of the page
 
+Quote Post
OpaQue
post Jul 27 2006, 03:07 AM
Post #2


Administrator
Group Icon

Group: Admin
Posts: 460
Joined: 26-August 04
Member No.: 1



Awesome presentation! I m impressed!
Go to the top of the page
 
+Quote Post
Chesso
post Jul 27 2006, 11:41 AM
Post #3


Teh Coder
Group Icon

Group: Members
Posts: 1,053
Joined: 18-April 06
From: Australia
Member No.: 12,833



Yep looks fairly good and structured to me. I think that code tag posted C code needs a bit of fixing though somehow because things are a little squished.

Perhaps a few more basic code examples would be nice for newcomers to try aswell?
Go to the top of the page
 
+Quote Post
dhanesh
post Jul 27 2006, 12:29 PM
Post #4


Binary Geek
Group Icon

Group: Members
Posts: 444
Joined: 4-November 05
From: The Digital Arena
Member No.: 9,440



Thankx Opaque & Chesso .. Yeah the code is kinda squished .. will try to fix that in my next posts .. as for a few basic examples .. I guess the post mastercomputers made would suffice. But if i am in the time zone again, i'd love to post a few basic examples of code in C. smile.gif

Regards
Dhanesh.

Go to the top of the page
 
+Quote Post
Omkar™
post Jul 27 2006, 02:44 PM
Post #5


Advanced Member
Group Icon

Group: Members
Posts: 130
Joined: 22-May 06
From: India
Member No.: 13,593




Great! I'm an 'A+' grader in C Programming, and that was quite a good head start!

Awaiting Part II (Or maybe can I write it? wink.gif )
Go to the top of the page
 
+Quote Post
dhanesh
post Jul 27 2006, 03:01 PM
Post #6


Binary Geek
Group Icon

Group: Members
Posts: 444
Joined: 4-November 05
From: The Digital Arena
Member No.: 9,440



QUOTE(Omkar™ @ Jul 27 2006, 06:44 PM) *

Great! I'm an 'A+' grader in C Programming, and that was quite a good head start!

Awaiting Part II (Or maybe can I write it? wink.gif )

Dude .. go on ! no permission needed .. if you can get to the level of a newbie .. then go ahead. It sucks when it conmes to being a n00b at things, and only 10% "TRY" to help you .. 5% "WANT" to help you.

I actualy am in the middle of writing the second part right now, so if u want to add up .. or start a new one .. please do so .. dont ask wink.gif ..

Regards
Dhanesh.

Go to the top of the page
 
+Quote Post
lonebyrd
post Jul 28 2006, 03:35 PM
Post #7


Premium Member
Group Icon

Group: Members
Posts: 302
Joined: 23-February 06
From: Northeastern Connecticut USA
Member No.: 11,487



I'm sorry, but most of that looked greek to me. I know a little scripting: alot of HTML, some php, but most of that, I did not get. Maybe I just did not get enough sleep last night. I was up early this morning. But I know it must be hard trying to teach an absolute beginner to something.
Go to the top of the page
 
+Quote Post
Quatrux
post Jul 28 2006, 04:28 PM
Post #8


the Q
Group Icon

Group: [HOSTED]
Posts: 1,051
Joined: 13-July 05
From: Lithuania, Vilnius
Member No.: 7,059



Well done, this is quite informative tutorial, especially for beginners and maybe average ones to get over it again, even though I never got into c, but I used to play around with it, but mostly on Amiga OS and Linux, somehow I moved to PHP+MySQL and didn't do anything special with c. In addition, c is so similar to PHP, the syntax and most of us I guess knows why biggrin.gif

This post has been edited by Quatrux: Jul 28 2006, 04:34 PM
Go to the top of the page
 
+Quote Post
Chesso
post Jul 28 2006, 10:25 PM
Post #9


Teh Coder
Group Icon

Group: Members
Posts: 1,053
Joined: 18-April 06
From: Australia
Member No.: 12,833



If you are ever up for dHanesh a beginners guide to C++/Win32 programming would be absoolutely great, I know how difficult it is to get started with programming the Win32 API for a basic GUI.

It'd be a fair bit larger of a tutorial heh heh but well worth it if done well. You could always get feedback from members here on it too and make it even better smile.gif
Go to the top of the page
 
+Quote Post
iGuest
post Nov 30 2007, 09:39 AM
Post #10


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



Your tutorial in 'see'language is very nice.I want to learn 'see' language by your toturial. good afternoon & have a nice day.

-dilip rajpurohit
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. [tutorial] Basics Of C Programming - Part 2(20)