Wednesday, November 12, 2014

C Programming Variables and Constants

C Programming Variables and Constants

Variables

Variables are memory location in computer's memory to store data. To indicate the memory location, each variable should be given a unique name called identifier. Variable names are just the symbolic representation of a memory location. Examples of variable name: sum, car_no, count etc.

int num;
Here, num is a variable of integer type.

Rules for writing variable name in C

  1. Variable name can be composed of letters (both uppercase and lowercase letters), digits and underscore '_' only.
  2. The first letter of a variable should be either a letter or an underscore. But, it is discouraged to start variable name with an underscore though it is legal. It is because, variable name that starts with underscore can conflict with system names and compiler may complain.
  3. There is no rule for the length of length of a variable. However, the first 31 characters of  a variable are discriminated by the compiler. So, the first 31 letters of two variables in a program should be different.
In C programming, you have to declare variable before using it in the program.

Constants

Constants are the terms that can't be changed during the execution of a program. For example: 1, 2.5, "Programming is easy." etc. In C, constants can be classified as:

Integer constants

Integer constants are the numeric constants(constant associated with number) without any fractional part or exponential part. There are three types of integer constants in C language: decimal constant(base 10), octal constant(base 8) and hexadecimal constant(base 16) .
Decimal digits: 0 1 2 3 4 5 6 7 8 9
Octal digits: 0 1 2 3 4 5 6 7
Hexadecimal digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F.
For example:
Decimal constants: 0, -9, 22 etc
Octal constants: 021, 077, 033 etc
Hexadecimal constants: 0x7f, 0x2a, 0x521 etc
Notes:
  1. You can use small caps a, b, c, d, e, f instead of uppercase letters while writing a hexadecimal constant.
  2. Every octal constant starts with 0 and hexadecimal constant starts with 0x in C programming.

Floating-point constants

Floating point constants are the numeric constants that has either fractional form or exponent form. For example:
-2.0
0.0000234
-0.22E-5
Note:Here, E-5 represents 10-5. Thus, -0.22E-5 = -0.0000022.

Character constants

Character constants are the constant which use single quotation around characters. For example: 'a', 'l', 'm', 'F' etc.

Escape Sequences

Sometimes, it is necessary to use newline(enter), tab, quotation mark etc. in the program which either cannot be typed or has special meaning in C programming. In such cases, escape sequence are used. For example: \n is used for newline. The backslash( \ ) causes "escape" from the normal way the characters are interpreted by the compiler.
Escape Sequences
Escape SequencesCharacter
\bBackspace
\fForm feed
\nNewline
\rReturn
\tHorizontal tab
\vVertical tab
\\Backslash
\'Single quotation mark
\"Double quotation mark
\?Question mark
\0Null character

String constants

String constants are the constants which are enclosed in a pair of double-quote marks. For example:
"good"                  //string constant
""                     //null string constant
"      "               //string constant of six white space
"x"                    //string constant having single character.
"Earth is round\n"         //prints string with newline

Enumeration constants

Keyword enum is used to declare enumeration types. For example:
enum color {yellow, green, black, white};
Here, the variable name is color and yellow, green, black and white are the enumeration constants having value 0, 1, 2 and 3 respectively by default. For more information about enumeration, visit page: Enumeration Types.

C Programming

C Programming Keywords and Identifiers Character set

<b>
C Programming Keywords and Identifiers
Character set</b>

Character set are the set of alphabets, letters and some special characters that are valid in C language.

Alphabets:

Uppercase: A B C  ....................................  X Y Z

Lowercase: a b c  ......................................  x y z

Digits:

0 1 2 3 4 5 6  8 9

Special Characters:
Special Characters in C language, &lt; &gt; . _ ( ) ; $ : % [ ] # ?
' &amp; { } " ^ ! * / | - \ ~ + 

White space Characters:

blank space, new line, horizontal tab, carriage return and form feed
Keywords:

Keywords are the reserved words used in programming. Each keywords has fixed meaning and that cannot be changed by user. For example:

int money;

Here, int is a keyword that indicates, 'money' is of type integer.

As, C programming is case sensitive, all keywords must be written in lowercase. Here is the list of all keywords predefined by ASCII C.
Keywords in C Languageauto double int struct
break else long switch
case enum register  typedef
char extern return union
continue for signed void
do if static  while
default goto sizeof volatile
const float short unsigned

Besides these keywords, there are some additional keywords supported by Turbo C.
Additional Keywords for Borland Casm far interrupt pascal near huge cdecl

All these keywords, their syntax and application will be discussed in their respective topics. However, if you want brief information about these keywords without going further visit page: list of all C keywords.
Identifiers

In C programming, identifiers are names given to C entities, such as variables, functions, structures etc. Identifier are created to give unique name to C entities to identify it during the execution of program. For example:

int money;
int mango_tree;

Here, money is a identifier which denotes a variable of type integer. Similarly, mango_tree is another identifier, which denotes another variable of type integer.

Rules for writing identifier

    An identifier can be composed of letters (both uppercase and lowercase letters), digits and underscore '_' only.
    The first letter of identifier should be either a letter or an underscore. But, it is discouraged to start an identifier name with an underscore though it is legal. It is because, identifier that starts with underscore can conflict with system names. In such cases, compiler will complain about it. Some system names that start with underscore are _fileno, _iob, _wfopen etc.
    There is no rule for the length of an identifier. However, the first 31 characters of an identifier are discriminated by the compiler. So, the first 31 letters of two identifiers in a program should be different.

Tips for Good Programming Practice :

Programmer can choose the name of identifier whatever they want. However, if the programmer choose meaningful name for an identifier, it will be easy to understand and work on, particularly in case of large program.
Next Page ►

Getting Started With C..





Getting Started With C..

In order to run a C program, you need a compiler. Compiler change source code(code written by programmer) to object code(code that computer understands) and creates executable file. There are many free and professional compilers available. For the sake of this course, GNU GCC compiler is used. All the examples in this course are tested and verified in GNU GCC compiler.

C Programming Tutorial

C Programming Tutorial

C programming is a popular computer programming language which is widely used for system and application software. Despite being fairly old programming language, C programming is widely used because of its efficiency and control. This tutorial is intended for beginners who does not have any prior knowledge or have very little knowledge of computer programming. All basic features of C programming language are included in detail with explanation and output to give you solid platform to understand C programming.

How To Start Programming

How To Start Programming

If you have ever wondered where to start when it comes to programming, this website will answer all of your questions. You are never too old or too young to start programming and it is not as hard as you think. Computer Programming is a subject that people are generally afraid of, the idea of typing in codes line after line sounds both boring and confusing, but the ability to create software is really fun and will give you a whole new view on how computers work. And hey, imagine going to a job interview and saying that you enjoy Computer Programming in your spare time! Being able to develop software is a skill that comes with great benefits and a skill that is actually not hard to learn. This website will provide you with free tutorials and resources that will teach you all of the skills that you need to know in order to be able to develop your own applications.

There are thousands of websites on the internet that claim to help you start programming, so why should you use this one? This website is dedicated to supplying you relevant content with relevant information. All of the tutorials are aimed at people with little to no experience at all. Other websites will throw confusing technical terms at you and expect you to understand them which will confuse you and interrupt your learning experience, we make sure that our content can be understood by anybody. And don’t be scared away if you already have programming experience, we don’t miss anything out!
What We Offer

Although learning how to program is fun and easy, it isn’t going to be a walk in the park. We supply you with videos, source codes, project files, e-books and much more to make sure that your road to becoming a computer programmer is as comfortable as possible. And the best part is, we offer all of this for free! You can go and waste your money on expensive books and memberships but why spend your money when you can get all of that information right here for free? All of the content on How To Start Programming™ is unique and created by experienced professionals so you can be sure that what you are learning is going to be useful.
Ready To Begin?

Now that you have a basic understanding of what this website is about, you should feel confident about making the first step.To begin your journey, navigate to the Getting Started page to start your first Computer Programming Tutorial. This website will be updated daily with fresh content so be sure to bookmark the page and subscribe to the RSS Feed.

Tutorials



Welcome to the
BASIC Programming Tutorial
 Show Index



This tutorial is provided to give you an understanding of how to program in the BASIC language.  It starts out explaining the basics of programming and progresses slowly into how to write video games.

This website also includes lots of heavily commented! game examples and (sort-of) tutorials on how to go about making some of the more popular types of games, such as Tetris or Asteroids for example.  Check out the links on the left for the examples.  If there are no links to the left, click on Show Index to reload the page.

All of the examples used in this tutorial are written for the BlitzBASIC programming language.   You can find yourself a copy of BlitzBASIC here if you wish.  However, some of these examples should 'work' in other BASIC languages (with a little modification if necessary).  Even if they don't work perfectly in your favorite BASIC compiler, download the free demo of BlitzBASIC anyways and try them out with that compiler.  It's wonderfully easy to use and it's free for 30 days!  Not to mention that it's specifically designed for making video games, which is why I like it so much :)

We also have a forum for anyone that wants to ask specific questions about anything they've found or had trouble with on this website.  And if you're feeling generous, feel free to answer other peoples questions in the forum.

This tutorial is always a work in progress...