50+ Top C Interview Questions and Answers in 2022

By | May 13, 2022
C Interview Questions and Answers

If you are a computer science student, you must have heard of the C programming language or may have some experience working with it. C is one of the most popular programming languages, and it is a general-purpose, statically-typed language that follows multiple programming paradigms, including procedural programming.

It is important for developers to have some knowledge of C as it is the building block of many popular programming languages, such as C++, C#, Java, and Python. If you have mentioned C programming as a skill in your CV, then the interviewer is definitely going to ask you some questions about it.

In this article, we have discussed the top C interview questions that are frequently asked during the interviews. Also, we have mentioned an appropriate answer to each question so that it could help you refresh your knowledge of the C programming language.

So, let’s not waste any more time and get started!

C Interview Questions and Answers

1. Who is the creator of the C programming language?

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

2. What is the latest version of C?

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

3. Give some key features of C.

Answer:

Vamware
  • 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 because it follows the procedural concept.
  • It offers high code security.

4. What does the break keyword do in C?

Answer: The break keyword is used to break a loop or switch statement in a C program.

5.  How many reserved keywords does C have?

Answer: 32

Vamware

6. What is the ASCII full form?

Answer: American Standard Code for Information Interchange.

7. What is the default value of the int static variable?

Answer: 0

8. How \(backslash) used in printf()?

Answer: \(backslash) use in escaping.

e.g.

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

9. 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. On the other hand, N+1 needs to run multiple operations.

Vamware

10. Give some differences between local and global variables.

Answer: Local variables are declared inside a function, whereas global variables are declared outside a function. Only the function that declared a local variable can access it. On the contrary, any function in a program can use a global variable. Check Local vs Global Variable

11. What is a pointer?

Answer: A pointer is a variable that contains the address of some other variable.

e.g.

int **pointer

12. What is the base address of an array?

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

13. Does the main() function need to compile a program?

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

14. What is a structure in C?

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

15. What is a prefixed increment?

Answer: In a prefixed increment, the value of the variable increases by one.

e.g.

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

16. 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 advantage 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.

17. Can we create a new header file?

Answer: Yes.

18. What is a dangling pointer?

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

19. 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];

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

Answer: Modifiers are the prefix of a data type in C that helps 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

21. What is typecasting in C?

Answer: 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);

22. What is an Infinite loop?

Answer: Infinite loop is a loop that runs continuously for an infinite time as the loop statement never gets false.

e.g.

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

23. What do malloc() and calloc() functions do?

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

The malloc() allows to reserve a single block of memory and return a pointer whereas calloc() helps to allocate multiple blocks of memory.

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

24. What is a NULL pointer?

Answer: Many times we require a pointer that points to nothing, in such cases we can use a NULL pointer. A NULL pointer is simply a pointer that points to nothing. It is mostly used in the linked list.

25. 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.

26. 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 used by iOS for its applications. Apple iOS uses Swift and Objective C to build iOS software and applications. If you want to appear in an interview for the job role of Objective-C developer, you need to consider the following Objective-C interview questions:

Objective C Interview questions

27. What is OOP?

Answer: OOP or Object-Oriented Programming is a programming model that uses classes and objects to create a program. Here an object is a data field that can have unique attributes and behavior.

28. What is Objective C?

Answer: Objective C is a programming language used to design macOS and iOS software. It is a superset of the C language because it offers all the features that C has, plus it supports object-oriented programming and a dynamic runtime.

29. What is Polymorphism?

Answer: Polymorphism is a concept in OOPs which says that the same operator can perform different operations on different data types.

30. What is Dot Notation?

Answer: Class instances or objects use dot notation to invoke the class attributes, properties, and methods.

31. What is Abstraction?

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

32. Who designed Objective-C?

Answer: Tom Love and Brad Cox.

33. What is the paradigm of Objective-C?

Answer: Objective C is a reflective, class-based object-oriented programming language.

34. 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 as interface or trait.

35. Name the protocols that Objective C uses.

Answer:

  • Ad hoc protocols a.k.a. informal protocols
  • Compiler-enforced protocol a.k.a. formal protocols

36. Name Objective C components.

Answer:

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

37. Why do we use #import in Objective C?

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

38. What is the difference between #import and #include?

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

39. 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.

40. What is the use of Category in Objective C?

Answer: Categories make it possible to add extra functionality to an object without making any changes to it.

41. 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.

42. What does @synthesize do in Objective-C?

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

43. What is Fast enumeration in Objective C?

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

44. 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 as follows:

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

45. 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]

46. What is the difference between copy and readonly?

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

47. What is NSObject in Objective C and what is 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.

48. 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.

49. How do we create a string object in Objective C?

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

50. What is the difference between function calls and messages?

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

51. What is id in Objective C?

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

52. 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.

53 What is a Responder Chain in Objective C?

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

54. Does the Objective C support method or function overloading?

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

55. What is Cocoa?

Answer: Cocoa is an application environment that helps to create macOS and iOS applications.

Conclusion

C does not allow to build mainstream applications or software but developers use it to write the script for operating systems. As C language allows programmers to interact with the hardware and its code executes very fast, it becomes an apt choice for creating high-quality operating systems. In many interviews related to operating systems, you may face questions from C, so you need to prepare yourself accordingly.

All the C interview questions that we have mentioned above can help you crack your next interview. While there is no certainty that the interviewer will ask you the exact same questions that we have discussed, the idea here is to make you familiar with the various types of C questions that you can expect during the interview.

If you have any suggestions related to this topic, please share them with us in the comments section below.

People are also reading:

Leave a Reply

Your email address will not be published.