1) What Is C Language?

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

1) What is C language?

C is a mid-level and procedural programming language. The Procedural


programming language is also known as the structured programming language is a
technique in which large programs are broken down into smaller modules, and each
module uses structured code. This technique minimizes error and misinterpretation.

2) Why is C known as a mother language?


C is known as a mother language because most of the compilers and JVMs are
written in C language. Most of the languages which are developed after C language
has borrowed heavily from it like C++, Python, Rust, javascript, etc. It introduces new
core concepts like arrays, functions, file handling which are used in these languages.

3) Why is C called a mid-level programming


language?
C is called a mid-level programming language because it binds the low level and
high -level programming language. We can use C language as a System
programming to develop the operating system as well as an Application
programming to generate menu driven customer driven billing system.

4) Who is the founder of C language?


Dennis Ritchie.

5) When was C language developed?


C language was developed in 1972 at bell laboratories of AT&T.

6) What are the features of the C language?


The main features of C language are given below:

o Simple: C is a simple language because it follows the structured approach, i.e.,


a program is broken into parts
o Portable: C is highly portable means that once the program is written can be
run on any machine with little or no modifications.
o Mid Level: C is a mid-level programming language as it combines the low-
level language with the features of the high-level language.
o Structured: C is a structured language as the C program is broken into parts.
o Fast Speed: C language is very fast as it uses a powerful set of data types and
operators.
o Memory Management: C provides an inbuilt memory function that saves the
memory and improves the efficiency of our program.
o Extensible: C is an extensible language as it can adopt new features in the
future.

7) What is the use of printf() and scanf() functions?


printf(): The printf() function is used to print the integer, character, float and string
values on to the screen.

Following are the format specifier:

o %d: It is a format specifier used to print an integer value.


o %s: It is a format specifier used to print a string.
o %c: It is a format specifier used to display a character value.
o %f: It is a format specifier used to display a floating point value.

scanf(): The scanf() function is used to take input from the user.

8) What is the difference between the local


variable and global variable in C?
Following are the differences between a local variable and global variable:

Basis for Local variable Global variable


comparison

Declaration A variable which is declared inside A variable which is declared


function or block is known as a local outside function or block is known
variable. as a global variable.

Scope The scope of a variable is available The scope of a variable is available


within a function in which they are throughout the program.
declared.

Access Variables can be accessed only by Any statement in the entire


those statements inside a function in program can access variables.
which they are declared.
Life Life of a variable is created when the Life of a variable exists until the
function block is entered and program is executing.
destroyed on its exit.

Storage Variables are stored in a stack unless The compiler decides the storage
specified. location of a variable.

9) What is the use of a static variable in C?


Following are the uses of a static variable:

o A variable which is declared as static is known as a static variable. The static


variable retains its value between multiple function calls.
o 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.
o The static variable is initially initialized to zero. If we update the value of a
variable, then the updated value is assigned.
o The static variable is used as a common value which is shared by all the
methods.
o The static variable is initialized only once in the memory heap to reduce the
memory usage.

10) What is the use of the function in C?


Uses of C function are:

o C functions are used to avoid the rewriting the same code again and again in
our program.
o C functions can be called any number of times from any place of our program.
o When a program is divided into functions, then any part of our program can
easily be tracked.
o C functions provide the reusability concept, i.e., it breaks the big task into
smaller tasks so that it makes the C program more understandable.

11) What is the difference between call by value


and call by reference in C?
Following are the differences between a call by value and call by reference are:

Call by value Call by reference

Description When a copy of the value is passed to When a copy of the value is passed to
the function, then the original value is the function, then the original value is
not modified. modified.

Memory Actual arguments and formal Actual arguments and formal


location arguments are created in separate arguments are created in the same
memory locations. memory location.

Safety In this case, actual arguments remain In this case, actual arguments are not
safe as they cannot be modified. reliable, as they are modified.

Arguments The copies of the actual arguments are The addresses of actual arguments
passed to the formal arguments. are passed to their respective formal
arguments.

Example of call by value:

1. #include <stdio.h>
2. void change(int,int);
3. int main()
4. {
5. int a=10,b=20;
6. change(a,b); //calling a function by passing the values of variables.
7. printf("Value of a is: %d",a);
8. printf("\n");
9. printf("Value of b is: %d",b);
10. return 0;
11. }
12. void change(int x,int y)
13. {
14. x=13;
15. y=17;
16. }

Output:

Value of a is: 10
Value of b is: 20

Example of call by reference:

1. #include <stdio.h>
2. void change(int*,int*);
3. int main()
4. {
5. int a=10,b=20;
6. change(&a,&b); // calling a function by passing references of variables.
7. printf("Value of a is: %d",a);
8. printf("\n");
9. printf("Value of b is: %d",b);
10. return 0;
11. }
12. void change(int *x,int *y)
13. {
14. *x=13;
15. *y=17;
16. }

Output:

Value of a is: 13
Value of b is: 17

12) What is recursion in C?


When a function calls itself, and this process is known as recursion. The function that
calls itself is known as a recursive function.

Recursive function comes in two phases:

1. Winding phase
2. Unwinding phase

Winding phase: When the recursive function calls itself, and this phase ends when
the condition is reached.

Unwinding phase: Unwinding phase starts when the condition is reached, and the
control returns to the original call.
Example of recursion

1. #include <stdio.h>
2. int calculate_fact(int);
3. int main()
4. {
5. int n=5,f;
6. f=calculate_fact(n); // calling a function
7. printf("factorial of a number is %d",f);
8. return 0;
9. }
10. int calculate_fact(int a)
11. {
12. if(a==1)
13. {
14. return 1;
15. }
16. else
17. return a*calculate_fact(a-1); //calling a function recursively.
18. }

Output:

factorial of a number is 120

13) What is an array in C?


An Array is a group of similar types of elements. It has a contiguous memory
location. It makes the code optimized, easy to traverse and easy to sort. The size and
type of arrays cannot be changed after its declaration.

Arrays are of two types:

o One-dimensional array: One-dimensional array is an array that stores the


elements one after the another.

Syntax:

1. data_type array_name[size];
o Multidimensional array: Multidimensional array is an array that contains
more than one array.

Syntax:

1. data_type array_name[size];

Example of an array:

1. #include <stdio.h>
2. int main()
3. {
4. int arr[5]={1,2,3,4,5}; //an array consists of five integer values.
5. for(int i=0;i<5;i++)
6. {
7. printf("%d ",arr[i]);
8. }
9. return 0;
10. }

Output:

1 2 3 4 5

14) What is a pointer in C?


A pointer is a variable that refers to the address of a value. It makes the code
optimized and makes the performance fast. Whenever a variable is declared inside a
program, then the system allocates some memory to a variable. The memory
contains some address number. The variables that hold this address number is
known as the pointer variable.

For example:

1. Data_type *p;

The above syntax tells that p is a pointer variable that holds the address number of a
given data type value.

Example of pointer
1. #include <stdio.h>
2. int main()
3. {
4. int *p; //pointer of type integer.
5. int a=5;
6. p=&a;
7. printf("Address value of 'a' variable is %u",p);
8. return 0;
9. }

Output:

Address value of 'a' variable is 428781252

15) What is the usage of the pointer in C?

o Accessing array elements: Pointers are used in traversing through an array of


integers and strings. The string is an array of characters which is terminated by
a null character '\0'.
o Dynamic memory allocation: Pointers are used in allocation and deallocation
of memory during the execution of a program.
o Call by Reference: The pointers are used to pass a reference of a variable to
other function.
o Data Structures like a tree, graph, linked list, etc.: The pointers are used to
construct different data structures like tree, graph, linked list, etc.

16) What is a NULL pointer in C?


A pointer that doesn't refer to any address of value but NULL is known as a NULL
pointer. When we assign a '0' value to a pointer of any type, then it becomes a Null
pointer.

17) What is a far pointer in C?


A pointer which can access all the 16 segments (whole residence memory) of RAM is
known as far pointer. A far pointer is a 32-bit pointer that obtains information
outside the memory in a given section.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy