




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The basics of C programming language, including C tokens, variables, data types, and constants. It explains the rules for declaring variables and the different data types that can be used in C. The document also covers how to declare variables as constants using the const keyword. It is a useful resource for beginners learning C programming language.
Typology: Study notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!
This chapter contains following topics:
C Tokens Variables DataTypes Backslash characters (escape sequences) Constants How to Declare Variables Use of scanf function
Introduction:
A program is a set of Instructions. These instructions are made using various words and symbols according some rules known as grammar (or syntax rules).
Like any other language, C has its own vocabulary and grammar. So, all these details are discussed in this chapter.
Character Set :
The characters are grouped in to following categories:
a. Upper Case: A to Z
b. Lower Case: a to z
2 ) Digits
a. All Decimal digits 0 to 9
4 ) White Spaces
a. Blank Space
b. Horizontal tab
c. Carriage Return
d. New Line
Example of valid Identifiers:
Example of invalid Identifiers:
int
$nos
no 1
no,
2sum
(sum)
Constants
An integer constant refers to a sequence of digits without fractional part. There are three types of integers: decimal integer, octal integer and hexadecimal integer.
Decimal integers consist of a set of digits, 0 through 9, preceded by optional + or -.
Backlash Character Constants:
C supports special backslash character constants that are used to display output in particular format. For example ‘\n’ is used to print the text in the next line.
List of backslash character are given as below:
\b For back space \n For back space \r Carriage Return \t Horizontal tab * To print Single quote in output \” To print Double quote in output ? To print Question mark in output. \ To print Back slash in output \0 To represent null character
A variable is a data name that can be used to store data value. A variable can store different value at different time.
Programmer can decide the variable name according to his/her choice but after satisfying the following rules of variables:
Rules of Variable:
Declaring variable as constant:
We can also declare variable to have constant value during the whole program by using const keyword.
For example: const int PI = 3.14;
const is new data type quantifier available in ANSI standard. It tells the compiler that value of PI remains 3.14 throughout the program. So we can’t change its value at any other place than declaration.
#include <stdio.h> int main() {
int number1, number2, sum;
printf("Enter two integers: "); scanf("%d %d", &number1, &number2);
// calculating sum sum = number1 + number2;
printf("%d + %d = %d", number1, number2, sum); return 0; }
OUTPUT WILL BE:
Enter two integers: 12 11 12 + 11 = 23