Basic Syntax in C Programming | Programming and Data Structures - Computer Science Engineering (CSE) PDF Download

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

Example: The following C statement consists of five tokens.

printf("Hello, World! ");

The individual tokens are:

printf
(
"Hello, World!
"
)
;

Question for Basic Syntax in C Programming
Try yourself:The number of tokens in the following C statement. 
printf("i = %d, &i = %x", i, &i);is
View Solution

➢ 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! 
");
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, 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 constants or variables or any other identifier names.

Basic Syntax in C Programming | Programming and Data Structures - Computer Science Engineering (CSE)

➢ 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.
The document Basic Syntax in C Programming | Programming and Data Structures - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Programming and Data Structures.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
119 docs|30 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Basic Syntax in C Programming - Programming and Data Structures - Computer Science Engineering (CSE)

1. What are tokens in C programming?
Ans. In C programming, tokens are the smallest individual units that make up a program. These units can be classified into five main categories: identifiers, keywords, constants, operators, and special symbols. Tokens are used to form statements and expressions in the C programming language.
2. Can you provide examples of tokens in C programming?
Ans. Yes, here are examples of tokens in C programming: - Identifiers: variables names like "count" or "sum" - Keywords: reserved words like "int" or "if" - Constants: numerical values like "10" or "3.14" - Operators: symbols used for arithmetic or logical operations like "+", "-", "*", or ">" - Special symbols: punctuation marks like "{" or ";"
3. What is the significance of tokens in C programming?
Ans. Tokens play a crucial role in C programming as they are the building blocks of a program. They determine the syntax and structure of the program. By combining tokens in a specific order, meaningful statements and expressions can be created. Understanding and manipulating tokens is essential for writing correct and effective C programs.
4. How are tokens separated in C programming?
Ans. In C programming, tokens are generally separated by whitespace characters like spaces, tabs, or line breaks. The whitespace characters act as delimiters between tokens. However, there are exceptions when certain tokens are written without any whitespace separation, such as "++" for the increment operator or "int" for the keyword.
5. Can tokens be modified or customized in C programming?
Ans. No, tokens cannot be modified or customized in C programming. They are predefined and have fixed meanings assigned by the C language specification. The C compiler recognizes these predefined tokens and interprets them accordingly. Modifying or customizing tokens would result in syntax errors and would not be recognized by the compiler.
119 docs|30 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Important questions

,

Basic Syntax in C Programming | Programming and Data Structures - Computer Science Engineering (CSE)

,

Viva Questions

,

past year papers

,

Sample Paper

,

Free

,

pdf

,

Previous Year Questions with Solutions

,

mock tests for examination

,

ppt

,

Basic Syntax in C Programming | Programming and Data Structures - Computer Science Engineering (CSE)

,

Semester Notes

,

Summary

,

Extra Questions

,

practice quizzes

,

study material

,

shortcuts and tricks

,

Objective type Questions

,

video lectures

,

Exam

,

MCQs

,

Basic Syntax in C Programming | Programming and Data Structures - Computer Science Engineering (CSE)

;