50+ Best C Interview Questions & Answers in 2021 [Updated]

By | September 28, 2021
C Interview Questions

If you are a Computer Science student, then you must have heard of the C programming language or may have some experience with it. There was a time when C was one of the most popular languages, but with the increasing demand for OOPs concepts, developers need to move to other high-level programming languages. It is also important for a developer to have some knowledge of C, because it is the building block of many popular programming languages such as C++, C#, Java, and Python. If you have mentioned C language with your other skills in your CV, then the interviewer definitely going to ask you some questions about it. Here we have selected Top C Programming Interview Questions which are mostly asked during the interviews.

C Interview Questions

Question: Who is the creator of the C programming language?

Answer: Dennis Ritchie invented the C programming language at Bell Labs.

Vamware

Question: What is the latest version of C?

Answer: C17 is the latest version of C, released in 2017.

Question: Give some key Features of C.

Answer:

  • It is portable which means code written on one computer can run on other computers.
  • It comes with a feature called Modularity which can break the programs into small modules.
  • The compiling speed of the C language is very high due to its Procedural Concept.
  • Code security is also good.

Question: What break keyword do in C?

Answer: A keyword break is used to break a loop or switch statement so that the and walk out from it.

Question:  How many reserved keywords C have?

Answer: 32

Question: What is the full form of ASCII?

Answer: American Standard Code for Information Interchange.

Question: What is the default value of int static variable?

Answer: 0

Question: How \(backslash) used in printf()?

Answer: \(backslash) use in escaping.

e.g.

printf(“hello \n world);
//output
hello
world

Question: Are N++ and N+1 take the same time to execute, if not why?

Answer: No, N++ and N+1 do not take the same time to execute. N++ can execute faster than N+1 because the N++ statement runs in a single instruction, but N+1 takes more operation to perform.

Question: Give some differences between local and global variables.

Answer: Local variables are declared inside the function, whereas the global variable declares outside the function. Only that function can access the local variable which had declared it, however, any function can use the global variable. Check Local vs Global Variable

Question: What is a pointer on a pointer?

Answer: A pointer variable that contains the address of another pointer variable.

e.g.

int **pointer

Question: What is the base address of an array?

Answer: The first element address of the array is known as the base address, and with the help of the base address we can find the address of the consecutive array elements.

Question: Does main() function require to compile a program?

Answer: No program can be compiled without the main() function, and it won’t execute.

Question: What is a structure in C?

Answer: A structure is a data structure in C which is a collection of heterogeneous data items.

Question: What is prefixed increment?

Answer: In a prefixed increment, the value of the variable increase first.

e.g.

int a=0;
++a   // increment operation.

Question: How dynamic data structure in C is efficient as compared to the static data structure?

Answer: The dynamic data structure shows their efficiency in memory allocation, which is the main asset of dynamic data structure over the static data structure. In the dynamic data structure, memory access only occurs when it’s needed, which prevents memory wastage.

Question: Can we create a new header file?

Answer: Yes.

Question: What is a dangling pointer?

Answer: A dangling pointer is a pointer to storage that is no longer allocated. For example, when a pointer is pointing a memory address of a variable, but when the variable is deleted and the pointer is still pointing to the memory location this pointer will be termed as a dangling pointer.

Question: What typedef keyword do in C?

Answer: typedef keyword is used to give an alternate name to a reserved datatype keyword.

e.g.

typedef unsigned char ch; 
// now ch has become a char data type
ch string1[20], string2[30];

Question: What are modifiers? Name some of the modifiers used in C.

Answer: Modifiers are the prefix of a data type that is used to modify the memory allocation of the datatype.

e.g.

long int a; 
//here long is a modifier and the “a”will occupy 8 bits of space in the memory.
Short int b;
// short is the modifier and “b” will occupy 2 bit of space in the memory

Modifiers:

  1. short
  2. long
  3. unsigned
  4. signed

Question: What is typecasting in C?

Answer: A typecasting is a method in C that can convert the data type of a variable into another data type.

e.g.

float a;
int b = (int) a;          // type casting from float to int
printf(“%d”, b);

Question: What is an Infinite loop?

Answer: When a loop runs continuously for infinite time or the loop statement never gets false is known as an infinite loop.

e.g.

int a =1;
while(a==1)
{ 
printf(“run infinite time”);
}

Question: What malloc() and calloc() function do?

Answer: Both malloc () and calloc () perform the same function, which is they provide dynamic memory allocation to a variable.

malloc() use to reserve a single block of memory and return a pointer whereas calloc() is used to allocates multiple block of memory.

// malloc() and calloc() syntax
Mptr = (int*) malloc(20*sizeof(int));
Cptr= (int*) calloc(20, sizeof(int));

Question: What is a NULL pointer?

Answer: Many times we require a pointer to points nothing that time we use a NULL pointer. A NULL pointer is that pointer that points to nothing. The NULL pointer mostly used in the linked list.

Question: Name the function used to convert a string to a number.

Answer:

  1. atof(): convert a string to afloat
  2. atoi(): convert a string to an integer
  3. atol(): convert a string to a long integer.

Question: What is #pragma?

Answer: The #pragma is a preprocessor directive that allows each compiler to implement compiler-specific features that can be turned on and off by using the #pragma statement.

Objective C

Objective C is an alternate programming language use by IOS system for their applications. Apple-IOS use Swift and Objective C to build IOS software and applications for their different devices. If you want to land in Apple company as an Objective-C developer here we have provided the most important Objective-C interview questions which will definitely help you crack the interview.

Objective C Interview questions

Question: What are OOPs?

Answer: Object-Oriented Programming is a model of programming languages that use class and objects to create the program. Here object can be defined as a data field that can have unique attributes and behavior.

Question: What is Objective C?

Answer: Objective C is a programming language used to design OS X and iOS software. It is a superset of the C language because it supports object-oriented programming and a dynamic runtime.

Question: What is Polymorphism?

Answer: Polymorphism is a concept in OOP’s which says that the same operator can perform a different kind of operations on different data types.

Question: What is Dot Notation?

Answer: Dot notation is used by the class instance or objects to invoke the class attributes, properties, and methods.

Question: What is Abstraction?

Answer: Abstraction is a technique of hiding unnecessary code from the user.

Question: Who designed Objective-C?

Answer: Tom Love and Brad Cox

Question: What is the paradigm of Objective-C?

Answer: Objective C is a Reflective, Class-Based Object-oriented programming language.

Question: What is the protocol in Objective C?

Answer: Objective C supports single inheritance but with the help of protocol, we can perform multiple inheritances. In other programming languages, it is known by interface or trait.

Question: Name the protocols that Objective C uses.

Answer:

  • Ad hoc protocols aka informal protocols
  • Compiler-enforced protocol aka formal protocols

Question: Name Objective C components.

Answer:

  • Preprocessor orders
  • Interface
  • Method
  • Variables
  • Statement and expression
  • Comments

Question: Why do we use #import in Objective C?

Answer: #import is used as an upgrade of #include that solves the problem of recursive include.

Question: What is the difference between #import and #include?

Answer: #import added in Objective C to replace #include because #include was not able to solve the problem of recursive include. #import makes sure that the file included in the source only once.

Question: What is an accessor method?

Answer: An access method related to an object which sets which value and property of a class can a class instance invokes.

Question: What is the use of Category in Objective C?

Answer: Categories are used to add extra functionality to an object without making any changes to it.

Question: What is NSArray in objective C?

Answer: In Objective C we use the Foundation Framework NSArray class to handle the Array objects. The NSArray contains many methods to create and manipulate arrays.

Question: What does @synthesize do in Objective-C?

Answer: The @synthesize creates accessor (getter and setter) methods for a variable.

Question: What is Fast enumeration in Objective C?

Answer: When we enumerate through a collection in objective C is known as fast enumeration.

Question: What are collections in Objective C name some of them?

Answer: A collection is a foundation framework object in Objective C that is used to store objects.

Some of the most important collections in Objective C are:

  • NSSet
  • NSArray
  • NSDictionary
  • NSMutableSet
  • NSMutableArray
  • NSMutableDictionary

Question: What is the syntax of method calling in Objective C?

Answer: Method calling syntax outside the class:

[class_name method_name]

Method calling in the same class:

[self method_name]

Question: What is the difference between copy and readonly?

Answer: When we use copy, it creates getters and setters whereas Readonly, only creates getters with no setters.

Question: What is NSObject in objective C and what its use?

Answer: NSObject is the root class of most Objective C classes and all other classes are derived from it. NSObject is used to allocate and initialize other objects like arrays, strings, dictionaries, etc.

Question: When would we use NSArray and NSMutableArray?

Answer:

  • NSArray: We use NSArray when we do not want any changes in the declared array items.
  • NSMutableArray: We use NSMutableArray when we want an array that declared items to be changed.

Question: How do we create a string object in Objective C?

Answer: We can use NSString and its sub-class NSMutableString to create string Objects.

Question: What is the difference between function calls and messages?

Answer: In a function call, the function and arguments linked together in compiled code whereas the message and receiving object do not link until the program gets executed.

Question: What is id in Objective C?

Answer: The id is a kind of pointer which points to an object in Objective C.

Question: What are the blocks in Objective C?

Answer: A block in Objective c helps to form a distinct segment of code that can be passed around the functions or methods as if they were values.

Question: What is a Responder Chain in Objective C?

Answer: When the responder objects get linked in series, they form a Responder chain, which starting point is a responder and endpoint is an app object. The responder chain is used to handle the event if the first responder would not able to handle the event, so the event gets passed to the second object present in the Responder chain.

Question: Does the Objective C support method or function overloading?

Answer: No, Objective C does not support function overloading so for each function we need to define different names.

Question: What is Cocoa?

Answer: Cocoa is an application Environment and covers Object-oriented parts that help to create OSX and iOS Applications.

Conclusion

However, C is not used to build mainstream applications or software, but still, developers use it to write the script for Operating systems. C is very close to hardware and its code executes very fast, which makes it a perfect programming language to create high-quality operating systems. In many interviews related to Operating systems, you may face questions from C, so it’s better to be prepared before you go for the interview. All the questions we have mentioned above will definitely be going to help you to crack the interview. There is no guaranty that the interviewer will ask you the same questions, the only purpose of these C interview questions to provide you with a basic understanding of what kind of questions you can expect during the interview.

If you like this article or have any suggestions, please comment down below and let us know.

People are also reading:

Leave a Reply

Your email address will not be published. Required fields are marked *