1) What is C Input/Output: printf() and scanf() functions?
The printf() and scanf() functions are used for input and output in C language and both functions are inbuilt library functions, declared in <stdio.h>
- printf() function: It is a C output function used to print or display output on the screen ("character, string, float, integer, octal and hexadecimal values."). Stands for print format.
- scanf() function: It is a C Input function used to take input from user. The scanf() reads formatted input fro the standard input such as Keyboards. Stands for scanf format.
2) What is format specifier?
The format specifier tell the compiler what type of data to be input using scanf() while taking input form user and what type of data to be output on the screen using printf() functions. For example
Following are the format specifier:
- %d: It is a format specifier used to print an integer value.
- %s: It is a format specifier used to print a string.
- %c: It is a format specifier used to display a character value.
- %f: It is a format specifier used to display a floating point value.
3) What is data type?
Data type define the type of data a variable can hold, for example an int variable can hold integer data, a char variable can hold character type data etc.
14) What is keywords?
Keywords are predefined, reserved words used in programming that has a special meaning to the complier. Keywords can be command or parameter they cannot be used as an identifier. For example int roll_no; here, int is a keyword that indicates roll_no is a variable of integer type.
5) What is identifier?
Identifier refers to a name given to entities such as variables, functions, structures etc. Identifiers must be unique. They are created to give a unique name to an entity to identify it during the execution of program.
6) What is variable?
Variable is a name given to a memory location, that is used to hold a value. For example: int roll_no; here, roll_no is a name of variable that can hold a integer value.
Each variable in C has a specific type, which determines the size and layout of the variable's memory.
7) What is local variable, global variable and static variable ?
Types of variables:
- Local variable: A variable which is declared inside function or block is known as a local variable. to
- Global variable: A variable which is declared outside of function or block is known as a global variable.
- Static variable: A variable which is declared as static is known as a static variable.
- Constant variable: Any variable declared with const keyword is known as constant variable, and the constant variables must be initialized while declared. Example: const int emp = 50577
8) Difference between local variable and global variable?
Following are the differences between a local variable and global variable:
Basis for comparison |
Local variable |
Global variable |
Declaration |
A
variable which is declared inside function or block is known as a local
variable. |
A
variable which is declared outside function or block is known as a global
variable. |
Scope |
The
scope of a variable is available within a function in which they are
declared. |
The
scope of a variable is available throughout the program. |
Access |
Variables
can be accessed only by those statements inside a function in which they are
declared. |
Any
statement in the entire program can access variables. |
Life |
Life
of a variable is created when the function block is entered and destroyed on
its exit. |
Life
of a variable exists until the program is executing. |
Storage |
Variables
are stored in a stack unless specified. |
The
compiler decides the storage location of a variable. |
9) What is the use of a static variable?
Following are the uses of a static variable:
- A variable which is declared as static is known as a static variable. The static variable retains its value between multiple function calls.
- Static variables are used because the scope of the static variable is available in the entire program. So, we can access a static variable anywhere in the program.
- The static variable is initially initialized to zero. If we update the value of a variable, then the updated value is assigned.
- The static variable is used as a common value which is shared by all the methods.
- The static variable is initialized only once in the memory heap to reduce the memory usage.
10) What is literal or literal constant?
Literal constant or literal: refer to fixed values or constants values assigned to the constant variables that cannot be modified during its execution. It also contains memory but does not have reference as variables. For example: const int = 5; is a constant integer expression in which 5 is an integer literal.
0 Comments:
Post a Comment
Please don't enter any spam link in the comment box.