C - Basic Syntax

You have seen the basic structure of a C program, so it will be easy to understand other basic building blocks of the C programming language.

Tokens in C

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 a 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.
Given below are two different statements −
printf("Hello, World! \n");
return 0;

Comments

Comments are like helping text in your C program and they are ignored by the compiler. They start with /* and terminate 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, 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, Manpowerand 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 constants or variables or any other identifier names.
autoelselongswitch
breakenumregistertypedef
caseexternreturnunion
charfloatshortunsigned
constforsignedvoid
continuegotosizeofvolatile
defaultifstaticwhile
dointstruct_Packed
double


Whitespace in C

A line containing only whitespace, possibly with a comment, is known as a blank line, and a C compiler totally ignores it.
Whitespace is the term used in C to describe blanks, tabs, newline characters and comments. Whitespace separates one part of a statement from another and enables the compiler to identify where one element in a statement, such as int, ends and the next element begins. Therefore, in the following statement −
int age;
there must be at least one whitespace character (usually a space) between int and age for the compiler to be able to distinguish them. On the other hand, in the following statement −
fruit = apples + oranges;   // get the total fruit
no whitespace characters are necessary between fruit and =, or between = and apples, although you are free to include some if you wish to increase readability.

Related Posts:

  • 8051 Led Blinking 8051 Ports 8051 has 32-gpio's grouped into 4-Ports namely P0-P3 as shown in the below table. PORTNumber of PinsAlternative Function P08 (P0.0-P0.7)AD0-AD7 (Address and Data bus) P18 (P1.0-P1.7)None P28 (P2.0-P2.7)A8-A15… Read More
  • 8051 8 Bit mode Interfacing LCD Display using Keil C – AT89C51 Liquid Crystal Display (LCD): 16x2 LCD can be interfaced with microcontroller in 4 Bit or 8 Bit mode. These differs in how data is send to LCD. In 8 bit mode to write a character, 8 bit ASCII data is send through the data l… Read More
  • Keil Setup For 8051 In this tutorial we see how to setup Keil4 for generating .hex file.Keil software can be downloaded from this link.Download and install the Keil C51 for 8051. Keil Setup Steps Step1: Open the Keil software and… Read More
  • PIC Microcontroller Software Setup MPlab In this tutorial we will see how to setup a Mplabx project to generate .hex file for Pic16f877a MPLABx Setup Steps Step1: Open the MPLABx software and select the New project from File Menu as shown below. Step2:&nbs… Read More
  • 8051 LED On OFF control with Pushbutton Hardware Connections: Push button switch is connected to the first bit of PORT 0 (P0.0) which is configured as an input pin. Which is connected to a pull up resistor as there is NO INTERNAL PULL UP RESISTORS FOR PORT… Read More

0 comments:

Post a Comment