0% found this document useful (0 votes)
4 views

Data Type 1

Uploaded by

tharukesh321
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Data Type 1

Uploaded by

tharukesh321
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Data type

• In computer programming, a data type is a classification that


specifies which type of value a variable can hold and what
operations can be performed on that value.

• Integer (int): Represents whole numbers without any


decimal points.
Example: int x = 5;

• Float (float) and Double (double): Represent numbers


with decimal points. The main difference is in their
precision, with double having higher precision.
Example: float y = 3.14;

• Character (char): Represents a single character, such as a


letter or a symbol.
Example: char c = 'A';

• String (string): Represents a sequence of characters.


Example: string text = "Hello, World!";

• Array: Represents a collection of elements of the same data


type.
Example: int[] numbers = {1, 2, 3, 4, 5};

Variable
• In computer programming, a variable is a named storage
location that can hold a value.

• Variables are fundamental to programming because they


allow developers to store and manipulate data in their
programs.

Declaration:
• Syntax: data_type variable_name;

Initialization:
• Syntax: data_type variable_name = value;

Assignment:
• Variables can be assigned values using the assignment
operator (=).

Naming Rules:
• Variable names must follow certain rules, depending on the
programming language.
• Typically, they can include letters, numbers, and
underscores, but they cannot start with a number.

Data Types:
• Variables have types (e.g., int, double, string), which
determine the kind of data they can store.

Constant
• A constant is a value that cannot be altered or modified
during the execution of a program.

• Constants are used to represent fixed values that remain the


same throughout the program's execution.

• They provide a way to make code more readable,


maintainable, and to avoid magic numbers.

C-Tokens

A token is the smallest unit in the source code. Tokens can be


classified into several types.
Here are some common C tokens:

• Keywords:

• Keywords are reserved words that have special meanings in


C. Examples include int, float, if, for, while, etc.

• Identifiers:

• Identifiers are names given to various program elements,


such as variables, functions, arrays, etc. They must begin
with a letter or underscore, followed by letters, digits, or
underscores.

• Constants:

• Constants represent fixed values. There are different types


of constants, including:
▪ Integer constants (e.g., 10, -5)
▪ Floating-point constants (e.g., 3.14, -0.5)
▪ Character constants (e.g., 'A', '5')
▪ String constants (e.g., "Hello, World!")

• String Literals:
• Strings enclosed in double quotes, like "Hello, World!".

• Operators:

• Operators perform operations on variables and values.


Examples include +, -, *, /, %, ==, !=, &&, ||, etc.

• Punctuation Symbols:

• Symbols such as , (comma), ; (semicolon), ( and )


(parentheses), { and } (curly braces), [ and ] (square
brackets).

You might also like