WHAT'S NEW?
Loading...

Fundamentals Of C Programming

Character Sets Used In C

  • A digits from 0 to 9 
  • An uppercase letter from A to Z and lowercase letter from a to z. 
  • A special symbols like $, *, /, #, (, +, ), =, {, }, [, ], <, >, ', ", !, &, |, _, ^, ~, \, ., ;, :, ? etc. 

Comments

Comments  may be included in a C program to describe what is function is supposed to do, or perhaps, to clarify some portion of code. A comment begins with the two-character symbol /* and is terminated by another two character symbol */. it can  occur anywhere that a space. Tab or newline (so called white space characters) can. For example:
1
2
3
4
5
6
7
8
/* This is our first program in C */ 
#include<stdio.h>    /* This is header file */ 
main(){   /* This is the main function */ 
	printf("Hello World"); 
	printf("\n Welcome to C Programming");   // \n is a newline character  
}

// End of the program 


C supports two types of comments single line comment and multi line comment. For single line comment we just use // (in line 5 and 8), and for multi line comment we use /* and */.

Keywords

Keywords are reserved words, which are reserved by the compiler. Keywords cannot be used as variable names. C programming has 32 keywords. The table below contains a list of C keywords.

auto break case char const continue default do
double else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union unsigned void volatile while

Data Types in C

Data types define the way in which values and range of values are represented in a system. C has very small yet expressive set of data types. The types it contains efficiently and effective represent all kind of values.
There are five different kinds of data types in C. They are char, int, float, double and void.

Data Type Memory Requirement Properties of Data Values
char 2 bytes Holds character values like 'A', '&' etc. based on ASCII format.
int 2 bytes It holds integer values like 10, 20, 30 etc. ,/td>
float 4 bytes It holds floating point values like 10.5, 2.67 etc.
double 8 bytes It is a double precision and it holds floating point values e.g 10E + 23
void 0 byte Nothing, a non-existent object.

Constants and Variables 

Constants and variables are the basic data objects manipulated in a program. Programs use these entities to store and represent values in the course of its execution.
Constant
A constant is a value that does not change during the program execution. A constant used in C does not occupy memory. There are four basic types of constants. They are:
a)  Integer constants
b) Floating point constants
c) Character constants
d) String literals


Variables
Variables are the names given to the stored region of memory. The values of a variable changes during the execution of the program. A constant represents how values are stored in memory and they do not need memory.

Variable Declaration
A variable declaration states the types of the variable and if necessary initializes the variable to a given value. A declaration of a variable also allocates memory for the variable.
for e.g.    a = 5;
               b = 10; 

Variable Name
Variable names give a user-friendly access to memory location. C specifies certain rules for formulating a variable name.
  1. The first 31 characters of the variable name should be unique. 
  2. Special characters like ?, %, ", etc, except '_' (underscore) are not allowed in a variable name. 
  3. As C is case sensitive language. 'Abc' is different from 'abc'. 
  4. Variable names should not start with numbers. 
  5. Variables should start with an alphabet or the special character '_'. (It is recommended not to use variable names starting with underscore '_' as library functions follow this convention). 

Statements 

 Statements  specify actions to be performed by the program. Statements in C can be simple or compound.
In the simplest case, a simple statement is an expression followed by a semicolon. For example the assignment expression.
          a = b + c;
becomes an assignment statement when it is followed by a semicolon, thus,
         a = b + c;
In C, the semicolon is used to terminate a statement. The main point here is that, in C, the semicolor is part of the statement.

A compound statement begins with a left brace, {, followed by any number of statements, and terminated by a right brace, }. The left and right braces are similar to begin and end of other languages. An example of a compound statements is:
              {
                        count = 0;
                        if(x>y)
                              max = x;
                        else
                              max = y;
              }

0 comments:

Post a Comment