You are on page 1of 2

What is file?discuss different file opening modes?

=A file is a container in a computer system for storing information. Files used in computers are similar in features to that of paper What is pointer? explain concept of array pointer?
documents used in library and office files. There are different types of files such as text files, data files, directory files, binary and
graphic files, and these different types of files store different types of information. In a computer operating system, files can be stored
on optical drives, hard drives or other types of storage devices.
=What is a Pointer? A pointer is a variable that stores
Advertisements
a memory address. Pointers are used to store the
*File opening modes=Mode
r+
Meaning of Mode
Open for both reading and writing.
addresses of other variables or memory items.
rb+
w+
Open for both reading and writing in binary mode.
Open for both reading and writing. Pointers are very useful for another type of
wb+ Open for both reading and writing in binary mode
parameter passing, usually referred to as Pass By
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Address. Pointers are essential for dynamic memory
Explain storage classes?
allocation.
=A storage class in C is used to represent additional information about a variable. *Array of Pointers in C
Storage class represents the scope and lifespan of a variable.
It also tells who can access a variable and from where?
In C, a pointer array is a homogeneous collection of
Auto, extern, register, static are the four different storage classes in a C program. indexed pointer variables that are references to a
A storage class specifier in C language is used to define variables, functions, and parameters.
auto is used for a local variable defined within a block or function memory location. It is generally used in C
register is used to store the variable in CPU registers rather memory location for quick access. Programming when we want to point at multiple
Static is used for both global and local variables. Each one has its use case within a C program.
Extern is used for data sharing between C project files. memory locations of a similar data type in our C
*principal features of each storage class which are commonly used in C programming
program. We can access the data by dereferencing
Storage Class Declaration Storage Default Initial Value Scope Lifetime the pointer pointing to it.
auto Inside a function/block Memory Unpredictable Within the
function/block Within the function/block
register Inside a function/block CPU Registers Garbage Within the Syntax:
function/block Within the function/block
extern Outside all functions Memory Zero Entire the file and other files
where the variable is declared as extern program runtime pointer_type *array_name [array_size];
Static (local) Inside a function/block Memory Zero Within the function/block
program runtime *include<stdio.h>
Static (global) Outside all functions Memory Zero
-------------------------------------------------------------------------------------------------------------------------------
#include<stdlib.h>
main()
What is function? explain recursion with example?
=In simple words, a function is a relationship between inputs where each input is related to
{
exactly one output. Every function has a domain and codomain or range. A function is generally int arr[5],i,sum=0;
denoted by f(x) where x is the input. The general representation of a function is y = f(x).
*Techopedia Explains Recursive Function printf(" Enter Five numbers : ");
Recursive functions in code often rely on loop setups, where the initial variable is called on for(i=0;i<5;i++)
multiple times while being altered by the loop. Simple examples of a recursive function include
the factorial, where an integer is multiplied by itself while being incrementally lowered. Many {
other self-referencing functions in a loop could be called recursive functions, for example, where
n = n + 1 given an operating range.
scanf("%d",&arr[i]);
}
In addition to simpler recursive functions, programmers and others have come up with much
more elaborate functions that also work through principles of recursion. Some, like the for(i=0;i<5;i++)
_______________________________________________________________________________ {
How to call function? with example? sum=sum+arr[i];
=We use the function name followed by the argument list in parentheses to call a function. For }
example, we can use the following code to call the sum function that we defined earlier: int a =
5; int b = 10; int c = sum(a, b); In this code, we are calling the sum function with a and b as its printf("\n The sum of the given 5 numbers is :
parameters.
*Syntax-
%d\n",sum);
Function name (parameters); system("pause");
Function calling method is two types -1) call by value 2) call by reference
}
Describe file handling function? What is Dynamic memory allocation?
=Basics of File Handling in C =Dynamic memory allocation is the process of
File handing in C is the process in which we create, open, assigning the memory space during the execution
read, write, and close operations on a file. C language time or the run time. Reasons and Advantage of
provides different functions such as fopen(), fwrite(), fread(), allocating memory dynamically: When we do not
fseek(), fprintf(), etc. to perform input, output, and many know how much amount of memory would be
different C file operations in our program. needed for the program beforehand.
*The process of file handling refers to how we store the *The Dynamic memory allocation enables the C
available data or info in a file with the help of a program. The programmers to allocate memory at runtime. malloc
C language stores all the data available in a program into a () − allocates a block of memory in bytes at runtime.
file with the help of file handling in C. This data can be calloc () − allocating continuous blocks of memory at
fetched/extracted from these files to work run time. realloc () − used for reduce (or) extend the
again in any program. allocated memory.
Describe pointer arithmetic with example?
=Pointer Arithmetics in C with Examples
Pointer Arithmetic is the set of valid arithmetic operations
that can be performed on pointers. The pointer variables
store the memory address of another variable. It doesn’t
store any value.

Hence, there are only a few operations that are allowed to


perform on Pointers in C language. The C pointer arithmetic
operations are slightly different from the ones that we
generally use for mathematical calculations. These operations
are:

Increment/Decrement of a Pointer
Addition of integer to a pointer
Subtraction of integer to a pointer
Subtracting two pointers of the same type
Comparison of pointers

You might also like