বুধবার, ৩ জুন, ২০১৫

Lesson 3: C – Basic Syntax



 
A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol. For example, the following C statement consists of five tokens:
printf("Hello, World! \n");
The individual tokens are:
printf
(
"Hello, World! \n"
) ;


Semicolons;

In C program, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity.

For example, following are two different statements:
printf("Hello, World! \n”);
retrun 0;

Comments

Comments are like helping text in your C program and they are ignored by the compiler. They start with /* and terminates with the characters */ as shown below:

/* my first program in C */

You cannot have comments within comments and they do not occur within a string or character literals.

Identifiers

A C identifier is a name used to identify a variable, function, or any other user- defined item. An identifier starts with a letter A to Z or a to z or an underscore _ followed by zero or more letters, underscores, and digits (0 to 9).

C does not allow punctuation characters such as @, $, and % within identifiers. C is a case sensitive programming language.

Thus, Manpower and manpower are two different identifiers in C. Here are some examples of acceptable identifiers:



mohd zara
abc
move_name a_
_123 myname50
_temp j
a23b9
retVal

 

Keywords

The following list shows the reserved words in C. These reserved words may not be used as constant or variable or any other identifier names.

auto
else

break
enum

case
extern

char
float

const
for

continue
Goto
 default
if

do
int

double
_Packed

long
switch

register
typedef

return
union

short
unsigned

signed
void

sizeof
volatile

static
while

struct









For more query please contact me on Facebook.
Mail me on Gmail.
Watch my YouTube videos for IT solutions.
And don't forget to leave a comment. 

মঙ্গলবার, ২ জুন, ২০১৫

Lesson 2: C – Program Structure



C Hello World Example


Before we study Basic building blocks of the C programming language, ley us look a bare minimum C program structure so that we can take it as reference in upcoming chapters.

A C program basically consists of the following parts:

  • Preprocessor Commands
  • Functions
  • Variables
  • Statements & Expressions
  • Comments

Let us look at a simple code that would print the words “Hello World!”:



Let us look various parts of the above program



  1. The first line of thee program #include <stdio.h> is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation.
  2. The next line int main() is the main function where program execution begins.
  3. The next line /* my first program in C*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program.
  4. The next line  printf(“Hello World!”) is another function available in C which causes the message “Hello World!” to be displayed on the screen.
  5. The next line return 0 terminates main() function and returns the value 0.

 






Compile & Execute C Program


Lets look at how to save the source code in a file, how to compile and run it. Following are the simple steps:

  1. Open your C/C++ compiler1 and add the above mentioned code.
  2. Save the file as Hello World.c
  3. Now Compile and run by clicking F9 (Code::Blocks).
  4. If there are no errors in your code the compiler will create a windows which will display "Hello World!".







To download the document Click Here
For more information contact Facebook or Gmail or Youtube