5 Questions
What is the built-in data type for Boolean values in C?
int
What is the correct syntax to declare multiple variables of the same data type in C?
int x, y, z;
What is the purpose of initialization in C?
To assign a default value to a variable and avoid undefined values
What is the scope of a variable declared inside a function in C?
Local
What is the difference between declaration and initialization in C?
Declaration specifies the data type, initialization assigns a value
Study Notes
Data Types
- C has several built-in data types:
- Integers:
int
,short
,long
,unsigned int
, etc. - Floating-point numbers:
float
,double
,long double
- Characters:
char
- Boolean: No built-in type, but often represented using
int
(0 for false, 1 for true) - Void:
void
(no value)
- Integers:
Declaration
- A variable must be declared before it can be used
- Declaration syntax:
data_type variable_name;
- Example:
int x;
- Example:
- Multiple variables can be declared in a single statement, separated by commas
- Example:
int x, y, z;
- Example:
Assignment
- Assignment operator:
=
- Syntax:
variable_name = value;
- Example:
x = 10;
- Example:
- Assignment can be done at declaration time or later in the code
Initialization
- Initialization is a combination of declaration and assignment
- Syntax:
data_type variable_name = value;
- Example:
int x = 10;
- Example:
- Initialization is optional, but recommended to avoid undefined values
Scope
- Scope refers to the region of the code where a variable is accessible
- Variables have one of the following scopes:
- Local: Variables declared inside a function or block, accessible only within that scope
- Global: Variables declared outside all functions, accessible from any function
- Static local: Variables declared inside a function, but retain their value between function calls
- External: Variables declared in one file, accessible from other files
Data Types
- C has several built-in data types, including integers, floating-point numbers, characters, and void.
- Integers can be
int
,short
,long
, orunsigned int
. - Floating-point numbers can be
float
,double
, orlong double
. - The character data type is
char
. - Boolean is not a built-in type, but often represented using
int
(0 for false, 1 for true). - The
void
data type has no value.
Declaration
- A variable must be declared before it can be used.
- The declaration syntax is
data_type variable_name;
. - Multiple variables can be declared in a single statement, separated by commas.
Assignment
- The assignment operator is
=
. - The assignment syntax is
variable_name = value;
. - Assignment can be done at declaration time or later in the code.
Initialization
- Initialization is a combination of declaration and assignment.
- The initialization syntax is
data_type variable_name = value;
. - Initialization is optional, but recommended to avoid undefined values.
Scope
- Scope refers to the region of the code where a variable is accessible.
- Variables have one of four scopes: local, global, static local, or external.
- Local variables are declared inside a function or block and are only accessible within that scope.
- Global variables are declared outside all functions and are accessible from any function.
- Static local variables are declared inside a function, but retain their value between function calls.
- External variables are declared in one file and are accessible from other files.
Learn about the built-in data types in C programming, including integers, floating-point numbers, characters, and more. Understand how to declare variables in C.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free