Top

C Programming

1.

What is the C language?

Ans:

C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, with a static type system. By design, C provides constructs that map efficiently to typical machine instructions. It has found lasting use in applications previously coded in assembly language. Such applications include operating systems and various application software for computer architectures that range from supercomputers to PLCs and embedded systems.

2.

Why is C known as a mother language?

Ans:

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 the C language has borrowed heavily from it. Few examples of languages that borrowed from C language are 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?

Ans:

C has the features of both assembly-level languages i.e low-level languages and higher-level languages. So that’s why C is generally called a middle-level Language. The user uses the C language for writing an operating system and generates a menu-driven customer billing system.

4.

When was C language developed?

Ans:

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

5.

Who is the founder of C language?

Ans:

Dennis Ritchie.

6.

What are the features of the C language?

Ans:

The main features of the C language are given below:

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

7.

What are the basic Datatypes supported in C Programming Language?

Ans:

The Datatypes in C Language are broadly classified into 4 categories. They are as follows:

  • Basic Datatypes
  • Derived Datatypes
  • Enumerated Datatypes
  • Void Datatypes

The Basic Datatypes supported in C Language are as follows:

Datatype Name Datatype Size Datatype Range
short 1 byte -128 to 127
unsigned short 1 byte 0 to 255
char 1 byte -128 to 127
unsigned char 1 byte 0 to 255
int 2 bytes -32,768 to 32,767
unsigned int 2 bytes 0 to 65,535
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long 4 bytes 0 to 4,294,967,295
float 4 bytes 3.4E-38 to 3.4E+38
double 8 bytes 1.7E-308 to 1.7E+308
long double 10 bytes 3.4E-4932 to 1.1E+4932

 

8.

What is the difference between the local variable and global variable in C?

Ans:

Following are the differences between a local variable and a global variable:

Basis for comparison Local variable Global variable
Declaration A variable that is declared inside a function or block is known as a local variable. A variable that 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 The life of a variable is created when the function block is entered and destroyed on its exit. The 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 are static variables and functions?

Ans:

The variables and functions that are declared using the keyword Static are considered as Static Variable and Static Functions. The variables declared using Static keyword will have their scope restricted to the function in which they are declared.

void f() { 
   static int i; 
   ++i; 
   printf(“%d “,i); 
}

 

10.

What is the use of a static variable in C?

Ans:

Following are the uses of a static variable:

  • A variable that 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 that is shared by all the methods.
  • The static variable is initialized only once in the memory heap to reduce memory usage.

Loading…
Tags: C Programming Interview Questions and Answers || C Programming Sort Questions and Answers || C Programming Detailed Questions and Answers || C Programming Tutorial