top of page
Anchor 1
Frequently Asked C Interview Question & Answers

What are different storage class specifiers in C

auto, register, static, extern are storage class specifiers in C.

Close

Explain Enumerated types in C language?

Enumerated types are used to define variables that can only assign certain discrete integer values throughout the program.

Enumeration variables are variables that can assume values symbolically

Declaration and usage of an Enumerated variable.

enum boolean

{

false;

true;

}; enum boolean

Close

What is recursion in C?

Recursion: A function, which calls itself, recursion is simple to write in the program but takes more memory space and time to execute.

Advantages of using recursion:-

  • Avoid unnecessary calling of functions

  • Substitute for iteration

  • Useful when applying the same solution

 

Factorial program in c using Recursion

#include <stdio.h>

int factorial(unsigned int i)

{

if(i <= 1)

{

return 1;

}

return i * factorial(i - 1);

}

int main()

{

int i = 15;

printf("Factorial of %d is %d\n", i, factorial(i));

return 0;

}

Close

What is a structure in C Language? How to initialise a structure in C?

A structure is a composite data type declaration that defines a physically grouped list of variables to be placed under one name in a block of memory, allowing the different variables to be accessed via a single pointer.

Defining a structure in C: In C language a structure is defined using struct keyword followed by variable or pointer name below is the basic syntax for declaring a structure in C language.

struct tag_name

{

type member1;

type member2;

/* declare as many members as desired, but the entire structure size must be known to the compiler. */

};

Close

What are Derived data types in C?

Derived data types are object types which are aggregates of one or more types of basic data types. Below is the list of derived datatype in C Language.

  • Pointer types

  • Array types

  • Structure types

  • Union types

  • Function types

Close

What are static variables in C?

C defines another class of variables called static variables. Static variables are of two types:

  • Static variables that are declared within a function (function static variables). These variables retain their values from the previous call, i.e., the values which they had before returning from the function.

  • File static variables: These variables are declared outside any function using the keyword static. File static variables are accessible only in the file in which they are declared. This case arises when multiple files are used to generate one executable code.

#include <stdio.h>

void PrintCount()

{

static int Count = 1;

//Count is initialized only on the first call

printf( "Count = %d\n", Count);

Count = Count + 1;

//The incremented value of Count is retained

}

int main()

{

PrintCount();

PrintCount();

PrintCount();

return 0;

}

Output:

Count = 1

Count = 2

Count = 3

 

The output of the program is a sequence of numbers starting with 1, rather than a string of 1′s. The initialization of static variable Count is performed only at the first instance of the function call. In successive calls to the function, the variable count retains its previous value. However, these static variables are not accessible from other parts of the program.

Close

Explain JDK, JRE and JVM?

JDK:

  • It stands for Java Development Kit.

  • It is the tool necessary to compile, document and package Java programs.

  • It contains JRE + development tools.

JRE:

  • It stands for Java Runtime Environment.

  • JRE refers to a runtime environment in which Java bytecode can be executed.

  • It’s an implementation of the JVM which physically exists.

JVM:

  • It stands for Java Virtual Machine.

  • It is an abstract machine. It is a specification that provides a run-time environment in which Java bytecode can be executed.

  • JVM follows three notations: Specification, Implementation, and Runtime Instance.

Close

Why Java is platform independent?

Java is called platform independent because of its byte codes which can run on any system irrespective of its underlying operating system.

Close

Explain public static void main(String args[]) in Java.

main() in Java is the entry point for any Java program. It is always written as public static void main(String[] args).

  • public: Public is an access modifier, which is used to specify who can access this method. Public means that this Method will be accessible by any Class.

  • static: It is a keyword in java which identifies it is class-based. main() is made static in Java so that it can be accessed without creating the instance of a Class. In case, main is not made static then the compiler will throw an error as main() is called by the JVM before any objects are made and only static methods can be directly invoked via the class. 

  • void: It is the return type of the method. Void defines the method which will not return any value.

  • main: It is the name of the method which is searched by JVM as a starting point for an application with a particular signature only. It is the method where the main execution occurs.

  • String args[]: It is the parameter passed to the main method.

Close

Why Java is not 100% Object-oriented?

Java is not 100% Object-oriented because it makes use of eight primitive data types such as boolean, byte, char, int, float, double, long, short which are not objects.

Close
bottom of page