C - Basic Syntax

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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).

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");

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.

Identifiers

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

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 */

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"); return 0;

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 long switch break enum register typedef case extern return union char float short unsigned const for signed void continue goto sizeof volatile default if static while do int struct _Packed double

Whitespace in C 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:

Whitespace in C

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;


Kaugnay na mga set ng pag-aaral

U-world Gen-Chem: Bonding Chemistry #3

View Set

Entrepreneurship Chapter 4 Test Review

View Set

Chap 64, Chapter 63, Chapter 62, Chapter 61

View Set

Chapter 26: The Child with a Genitourinary Alteration

View Set

MGMT 4900 multiple choice questions

View Set

Esthetics Milady Foundations CH 5 Infection Control

View Set