After Midsems Flashcards
What does Functions syntax consists of?
A function definition consists of function header and function body.
What does function header consists of?
● Return_type: The function always starts with a return type of the function.
But if there is no return value then the void keyword is used as the return
type of the function.
● Function_Name: Name of the function which should be unique.
● Parameters: Values that are passed during the function call.
What does function body consists of?
● Local Variable: A local declaration of the variables that are needed by the
function.
● Function Statements: The statements that perform the task of the function.
● Return Statements: It returns the value evaluated by the function.
Whats Function calling?
● To use a function, you will have to call that function to perform the defined
task.
● When a program calls a function, the program control is transferred to the
called function.
● A called function performs a defined task and when its return statement is
executed or when its function-ending closing brace is reached, it returns the
program control back to the main program.
● To call a function, you simply need to pass the required parameters along
with the function name, and if the function returns a value, then you can
store the returned value.
Show the memory layout in a C program
HEAP (Dynamic-Free Memory)
STACK (Local Variables)
GLOBAL(STATIC)
PROGRAM CODE
In how many ways can a value be passed in a function?
While calling a function, there are two ways in which arguments can be
passed to a function −
a. Call by value
b. Call by reference
What is Recursion!?
Recursion is the process which comes into existence when a function calls a
copy of itself to work on a smaller problem.
● Any function which calls itself is called recursive function, and such
function calls are called recursive calls.
Explain calling by reference in functions?
● Call by reference:
○ Both actual and formal parameters refers to same memory location.
○ This method copies the address of (&) an actual argument into the formal
parameter.
○ The value of the actual parameters can be modified by changing the
formal parameters since the address of the actual parameters is passed.
Explain calling by value in functions?
● Call by value:
○ This method copies the actual value of an argument into the formal
parameter of the function.
○ In this case, we can not modify the value of the actual parameter by the
formal parameter.
○ Different memory is allocated for actual and formal parameters since
What are local variables?
Variables that are declared inside a function or block are called local
variables.
● They can be used only by statements that are inside that function or block of
code.
● Also known as internal, private or automatic variable.
● Local variables are not known to functions outside their own.
Explain abt Global Variable
Global Variables
● Global variables are defined outside a function, usually on top of the
program.
● Global variables hold their values throughout the lifetime of your program
and they can be accessed inside any of the functions defined for the program.
● A program can have same name for local and global variables but the value
of local variable inside a function will take preference.
What are the 4 types of storage classes?
There are four types of storage classes in C
1. Automatic
2. External
3. Static
4. Register
Explain Automatic Storage classes
Storage Classes in C: Automatic
● Automatic variables are allocated memory automatically at runtime.
● The life of the automatic variables is limited to the block in which they are
defined.
● The scope of the automatic variables is limited to the block in which they
are defined.
● The automatic variables are initialized to garbage by default.
● The memory assigned to automatic variables gets freed upon exiting from
the block.
Explain Extern Storage classes
● The external storage class is used to tell the compiler that the variable
defined as extern is declared with an external linkage elsewhere in the
program.
● The variables declared as extern are not allocated any memory. It is only
declaration and intended to specify that the variable is declared elsewhere
in the program.
Explain Static Storage classes
Storage Classes in C: Static
● The variables defined as static specifier can hold their value between the
multiple function calls.
● Local Scope: Static local variables are available only to the function or the
block in which they are defined.
● Global Scope: Static global variables are available for the entire program.
● Default initial value of the static integral variable is 0 otherwise null.
● The keyword used to define static variable is static.
Explain Register Storage classes
The variables defined as the register is allocated the memory into the CPU
registers depending upon the size of the memory remaining in the CPU.
● Its scope is limited to the function it is defined in.
● Lifetime is till the end of the function block
● We can not dereference the register variables, i.e., we can not use &
operator for the register variable.
● The access time of the register variables is faster than the automatic
variables.
Methods to Pass an Array as an Argument are!?
Methods to Pass an Array as an Argument:
- return_type function(type arrayname[])
- return_type function(type arrayname[SIZE])
- return_type function(type *arrayname)
Methods to return an Array from a function are?
We can return an array from a function in C using four ways
1. Returning the array passed to function
2. Returning dynamically created array
3. Return array using static array
4. Returning array using struct
Explain pointers in C
The pointer in C language is a variable which stores the address of another
variable.
● This variable can be of type int, char, array, function, or any other pointer.
● The size of the pointer depends on the architecture usually 8 bytes.
Whats Deference operator?
● When used in declaration (int* ptr), it
creates a pointer variable.
● When not used in declaration, it act as a
dereference operator.