Top 150 C Interview Questions and Answers

Updated 12 Dec 2024

Q1. Write a code for the length of string without using strlen() function.

Ans.

Code to find length of string without using strlen() function.

  • Use a loop to iterate through each character of the string

  • Increment a counter variable for each character in the string

  • Stop the loop when the null character '\0' is encountered

  • Return the counter variable as the length of the string

View 2 more answers
Frequently asked in

Q2. What is c code in java

Ans.

C code in Java refers to the use of the Java Native Interface (JNI) to incorporate C code into Java programs.

  • C code in Java is typically used when performance optimization or low-level system access is required.

  • JNI allows Java programs to call C functions and use C libraries.

  • C code can be written separately and compiled into a shared library, which is then loaded and used by Java code.

  • JNI provides a way to pass data between Java and C, handle exceptions, and manage memory.

  • Exa...read more

View 1 answer
Frequently asked in

Q3. Why is c++ better than C?

Ans.

C++ is better than C due to its object-oriented programming features and better memory management.

  • C++ supports object-oriented programming while C does not.

  • C++ has better memory management with features like constructors and destructors.

  • C++ has more advanced features like templates and exceptions.

  • C++ is more versatile and can be used for both low-level system programming and high-level application development.

  • C++ has a larger standard library compared to C.

  • C++ allows for func...read more

Add your answer

Q4. Draw the flow chart for the following C program

Ans.

Flow chart for a C program

  • Identify the input and output

  • Determine the conditions and loops

  • Draw the flow chart accordingly

Add your answer
Frequently asked in
Are these interview questions helpful?

Q5. How can we Do Web development using C

Ans.

Web development using C involves using frameworks like CGI, FastCGI, or libraries like libmicrohttpd.

  • Use frameworks like CGI or FastCGI to handle HTTP requests and responses.

  • Utilize libraries like libmicrohttpd for creating web servers in C.

  • Implement server-side logic in C to generate dynamic web content.

  • Use HTML and CSS for front-end development alongside C for back-end logic.

Add your answer

Q6. What is c and what is routing

Ans.

C is a programming language and routing is the process of selecting the best path for network traffic.

  • C is a high-level programming language used for system programming and developing applications.

  • Routing is the process of selecting the best path for network traffic to reach its destination.

  • Routing protocols like OSPF, BGP, and EIGRP are used to determine the best path for network traffic.

  • Routing tables are used to store information about network topology and available paths....read more

Add your answer
Share interview questions and help millions of jobseekers 🌟

Q7. Data structures through c language

Ans.

Data structures in C language are essential for organizing and manipulating data efficiently.

  • Data structures like arrays, linked lists, stacks, queues, trees, and graphs are commonly used in C programming.

  • Arrays are used to store a collection of elements of the same data type.

  • Linked lists are used to store elements in a linear order.

  • Stacks and queues are used for storing elements in a last-in-first-out (LIFO) and first-in-first-out (FIFO) manner, respectively.

  • Trees and graphs...read more

Add your answer

Q8. What are storage classes in C?Explain

Ans.

Storage classes in C define the scope and lifetime of variables.

  • There are four storage classes in C: auto, register, static, and extern.

  • Auto variables are local to a block and have automatic storage duration.

  • Register variables are stored in CPU registers for faster access.

  • Static variables have a lifetime throughout the program and are initialized only once.

  • Extern variables are declared outside any function and can be accessed by any function in the program.

Add your answer
Frequently asked in

C Jobs

C++ Linux Embedded (Networking) 5-10 years
GlobalLogic
3.7
Bangalore / Bengaluru
AUTOSAR - QNX/ Adaptive (Embedded C++) 5-10 years
GlobalLogic
3.7
Bangalore / Bengaluru
Sales Officer 2-5 years
Ferrero India Pvt. Ltd.
3.7
Hyderabad / Secunderabad

Q9. What is the diff between c and c++

Ans.

C is a procedural programming language while C++ is an object-oriented programming language with features like classes and inheritance.

  • C is a procedural programming language while C++ is a multi-paradigm language with support for object-oriented programming.

  • C does not support classes and objects, while C++ does.

  • C uses structures for data organization, while C++ uses classes.

  • C does not have features like inheritance and polymorphism, which are present in C++.

  • C++ allows functio...read more

Add your answer
Frequently asked in

Q10. Write a C program that will COMPILE and RUN to reverse a string in-place

Ans.

C program to reverse a string in-place

  • Use two pointers, one at the beginning and one at the end of the string

  • Swap the characters at the two pointers and move the pointers towards each other until they meet

  • Handle odd-length strings by leaving the middle character in place

Add your answer
Frequently asked in

Q11. Difference between c,c++

Ans.

C is a procedural programming language, while C++ is an object-oriented programming language that is an extension of C.

  • C is a procedural programming language, focusing on functions and procedures.

  • C++ is an object-oriented programming language, allowing for classes, objects, and inheritance.

  • C++ is an extension of C, adding features like classes, templates, and exception handling.

Add your answer
Frequently asked in

Q12. What are key features of static storage class?

Ans.

Static storage class is used to declare variables that retain their values throughout the program execution.

  • Variables declared with static storage class have a lifetime that extends for the entire duration of the program.

  • They are initialized only once, at the start of the program execution.

  • Static variables are stored in the data segment of the memory.

  • They are not destroyed when a function is exited, allowing their values to be preserved for future function calls.

  • Static storag...read more

View 1 answer

Q13. c vs c++ diff

Ans.

C is a procedural programming language while C++ is an object-oriented programming language.

  • C is a procedural programming language, focusing on functions and procedures.

  • C++ is an object-oriented programming language, allowing for classes, objects, and inheritance.

  • C++ is an extension of C, adding features like classes, templates, and exception handling.

Add your answer
Frequently asked in

Q14. Implement bit fields and explain with a piece of code

Ans.

Bit fields are used to allocate specific number of bits in a structure to store and manipulate data efficiently.

  • Bit fields are declared using a colon (:) followed by the number of bits to allocate.

  • They can be used to represent flags, status bits, or any other data that can be stored in a limited number of bits.

  • Bit fields can help in reducing memory usage and improving performance.

  • Here's an example: struct Flags { unsigned int flag1 : 1; unsigned int flag2 : 1; };

  • In this examp...read more

Add your answer

Q15. How many classes are there in C? Explain.

Ans.

There are no classes in C as it is a procedural programming language.

  • C is a procedural programming language, not an object-oriented one.

  • It does not have the concept of classes or objects.

  • Instead, it uses functions and structures to organize code.

  • Structures can be used to create user-defined data types.

  • For example, a structure can be defined to represent a person with attributes like name, age, and address.

Add your answer
Frequently asked in

Q16. Write the any coding in c language?

Ans.

Here is a simple example of a C program that prints 'Hello, World!'

  • Declare a main function

  • Use the printf function to print 'Hello, World!'

  • Return 0 to indicate successful execution

View 1 answer
Frequently asked in

Q17. Explain a Storage classes

Ans.

Storage classes in software engineering determine the lifetime and visibility of variables.

  • Storage classes include auto, register, static, and extern.

  • Auto variables have local scope and are automatically initialized.

  • Register variables are stored in CPU registers for faster access.

  • Static variables retain their value between function calls.

  • Extern variables are declared in one file and can be accessed in other files.

View 2 more answers

Q18. Write a simple C program.

Ans.

A simple C program

  • Include the stdio.h header file

  • Declare the main function

  • Use printf() function to print output

  • Use scanf() function to take input

  • End the program with return 0;

Add your answer
Frequently asked in

Q19. How to find common elements from two arrays using C

Ans.

Finding common elements in two arrays of strings using C

  • Create two arrays of strings

  • Loop through each element of the first array

  • For each element, loop through the second array to check for a match

  • If a match is found, add it to a third array

  • Return the third array with common elements

Add your answer
Frequently asked in

Q20. What is c language? What is keyword in c language?

Ans.

C language is a high-level programming language used for developing software. Keywords are reserved words with predefined meanings.

  • C language is a general-purpose programming language.

  • It was developed in the early 1970s by Dennis Ritchie.

  • C language is widely used for system programming and embedded systems.

  • Keywords in C language cannot be used as variable names or identifiers.

  • Examples of keywords in C language include 'if', 'else', 'for', 'while', 'int', 'float', etc.

View 2 more answers

Q21. write a program on structure.? and by using pointers how we declare structures.

Ans.

A program on structures using pointers to declare them.

  • Use the 'struct' keyword to define a structure

  • Use the 'typedef' keyword to create a new type name for the structure

  • Use the '->' operator to access structure members through a pointer

  • Example: typedef struct { int x; int y; } Point; Point *p;

  • Example: p->x = 5; p->y = 10;

Add your answer

Q22. Does any libraries are required to perform c programming and what are they?

Ans.

Yes, some libraries are required for C programming such as stdio.h, math.h, string.h, etc.

  • stdio.h library is used for input/output operations

  • math.h library is used for mathematical operations

  • string.h library is used for string manipulation operations

Add your answer

Q23. Write a program to implement strcmp

Ans.

Program to implement strcmp

  • Use a loop to compare each character of the two strings

  • Return 0 if both strings are equal, -1 if s1s2

  • Handle null and empty strings appropriately

Add your answer

Q24. What is the use of printf() and scanf() function?

Ans.

printf() is used to print formatted output to the screen, while scanf() is used to read formatted input from the user.

  • printf() is used to display output on the screen in a formatted way.

  • scanf() is used to read input from the user in a formatted way.

  • Example: printf("Hello, World!"); will display 'Hello, World!' on the screen.

  • Example: scanf("%d", &num); will read an integer input from the user and store it in 'num'.

View 2 more answers

Q25. What are storage class specifiers in c?

Ans.

Storage class specifiers in C are used to define the scope and lifetime of variables.

  • There are four storage class specifiers in C: auto, register, static, and extern.

  • Auto variables are local to a block and have automatic storage duration.

  • Register variables are stored in CPU registers for faster access.

  • Static variables have a lifetime throughout the program and are initialized only once.

  • Extern variables are declared in one file and can be used in other files.

  • Storage class spec...read more

Add your answer

Q26. Do you know C Programming?

Ans.

Yes, I know C Programming.

  • I have experience in writing programs in C language.

  • I am familiar with the syntax and structure of C language.

  • I have worked on projects using C language, such as developing a simple calculator program.

  • I am comfortable with concepts such as pointers, arrays, and structures in C language.

Add your answer
Frequently asked in

Q27. What are features of C language ?

Ans.

C is a procedural programming language with low-level memory access and a rich set of operators.

  • C is a compiled language

  • C has a simple syntax and a small set of keywords

  • C supports pointers and manual memory management

  • C has a rich set of operators and control structures

  • C is widely used for system programming, embedded systems, and game development

Add your answer
Frequently asked in

Q28. Which are the four storage classes in C

Ans.

The four storage classes in C are auto, register, static, and extern.

  • Auto: default storage class for all local variables

  • Register: used to define local variables that should be stored in a register instead of RAM

  • Static: used to define local variables that retain their value between function calls

  • Extern: used to declare a global variable that is defined in another file

View 1 answer
Frequently asked in

Q29. Write a C program and explain each line to me

Ans.

A C program that needs to be written and explained line by line.

  • The program should be written in C language.

  • Each line of the program needs to be explained.

  • The program should use an array of strings.

  • The answer should be returned in JSON format.

Add your answer
Frequently asked in

Q30. How can we start the program in c language?

Ans.

To start a program in C language, we need to write a main function and compile the code.

  • Write the main function with the code to be executed

  • Compile the code using a C compiler

  • Execute the compiled program

  • Optionally, pass command line arguments to the program

Add your answer

Q31. Write the Test_and_Set program

Ans.

Test_and_Set program is used to ensure mutual exclusion in concurrent systems.

  • Test_and_Set is a hardware instruction that sets a memory location to a value and returns its old value.

  • The program uses a loop to repeatedly execute the Test_and_Set instruction until it returns 0.

  • The program then enters the critical section and sets the memory location back to 0 when done.

  • Example code: while(Test_and_Set(&lock)); //critical section lock = 0;

Add your answer
Frequently asked in

Q32. define structure and union in C

Ans.

Structure and union are two user-defined data types in C used to store multiple data types under a single variable name.

  • Structure is a collection of variables of different data types under a single name.

  • Union is similar to structure but all the variables share the same memory location.

  • Structures are used to represent complex data types like a student record or a book record.

  • Unions are used to save memory by sharing the same memory location for different variables.

  • Structures a...read more

Add your answer

Q33. Difference between delete and free

Ans.

Delete and free are both used to deallocate memory, but delete is used for objects created with new, while free is used for memory allocated with malloc.

  • delete is used in C++ to deallocate memory for objects created with new keyword

  • free is used in C to deallocate memory for memory blocks allocated with malloc function

  • delete calls the destructor of the object before deallocating memory

  • free does not call any destructor

  • delete is used for single objects, while delete[] is used fo...read more

Add your answer

Q34. What are static, volatile, const in C mean ?

Ans.

Static, volatile, const are C keywords used to define properties of variables.

  • Static: used to define a variable that retains its value between function calls

  • Volatile: used to indicate that a variable's value may change unexpectedly, e.g. in an interrupt

  • Const: used to define a variable whose value cannot be changed once initialized

Add your answer
Frequently asked in

Q35. why is main function required in c program

Ans.

Main function is required in C program as it is the entry point of the program.

  • Main function is where the program starts executing.

  • It contains the code that initializes variables, calls functions, and performs other necessary tasks.

  • Without main function, the program would not know where to start executing.

  • Main function must return an integer value to indicate the status of the program execution.

  • Example: int main() { // code here }

View 1 answer
Frequently asked in

Q36. Which language do you prefer to code in? "Have you read The C Programming Language book by Dennis Retchie?" Which technical book have you read recently?.-So you like C, have you ever thought of bringing up the...

read more
Ans.

Yes, I prefer coding in C and have read The C Programming Language book. I have also explored the concept of Inheritance in C.

  • I find C to be a powerful and efficient language for system programming.

  • Yes, I have read The C Programming Language book by Dennis Retchie and found it to be a great resource.

  • Recently, I have been exploring the concept of Inheritance in C through various online resources and tutorials.

  • While C does not have built-in support for Inheritance, it is possib...read more

Add your answer

Q37. Explain whole process for Example.c file to Example.exe conversion

Ans.

The process of converting Example.c file to Example.exe involves several steps.

  • Preprocessing: includes header file inclusion, macro expansion, and conditional compilation

  • Compilation: converts source code to object code

  • Linking: combines object code with libraries to create executable file

  • Debugging: identifying and fixing errors in code

  • Optimization: improving performance of executable file

Add your answer

Q38. int x:4; what does it mean ? a) x is a four digit number. b)x is four bit integer. c)x is cannot be greater than 4 digits. d)None of these

Ans.

b) x is four bit integer.

  • The statement 'int x:4;' indicates that x is a four bit integer.

  • A four bit integer can have values ranging from 0 to 15.

  • The colon followed by the number 4 specifies the number of bits allocated for x.

View 1 answer

Q39. Difference between arr and adr

Ans.

Arr and adr are both used in programming, but arr typically refers to an array while adr typically refers to an address.

  • Arr is commonly used to refer to an array in programming, which is a collection of elements stored in a contiguous memory location.

  • Adr is often used to refer to an address in programming, which is the location of a variable or data in memory.

  • For example, int arr[5] declares an array of integers with 5 elements, while int *adr declares a pointer to an integer...read more

Add your answer

Q40. Who is the founder of c language?

Ans.

The founder of C language is Dennis Ritchie.

  • Dennis Ritchie is the creator of the C programming language.

  • He developed C language at Bell Labs in the early 1970s.

  • C language is widely used for system programming and developing other programming languages.

View 1 answer

Q41. What are the criteria for c program

Ans.

Criteria for C program include syntax correctness, logical flow, and efficient memory usage.

  • Correct syntax and logical flow are essential for program functionality

  • Efficient memory usage is important for performance optimization

  • Program should be well-documented and easy to maintain

  • Code should be modular and reusable for future projects

Add your answer

Q42. What is static variable in C? with program

Ans.

A static variable in C is a variable that retains its value between function calls.

  • Static variables are declared using the 'static' keyword.

  • They are initialized only once, at the start of the program.

  • Their value persists even after the function call ends.

  • Static variables have a default initial value of 0.

  • They are useful for maintaining state across function calls.

Add your answer
Frequently asked in

Q43. Can I declare a structure called ‘a’ which contains a structure called ‘b’ and ‘b’ in turn contains ‘a’?

Ans.

Yes, it is possible to declare a structure 'a' that contains a structure 'b' and 'b' in turn contains 'a'.

  • To achieve this, we can use forward declaration of one of the structures.

  • By using a pointer or reference to the other structure inside the first structure, we can avoid recursive definition.

  • This allows us to create a nested structure hierarchy.

Add your answer
Frequently asked in

Q44. What is the difference between into arr [5] and malloc (5*sizeof (int))

Ans.

The difference is that 'int arr[5]' creates an array on the stack, while 'malloc(5*sizeof(int))' allocates memory on the heap.

  • int arr[5] creates an array of 5 integers on the stack, which is a fixed-size memory allocation.

  • malloc(5*sizeof(int)) dynamically allocates memory on the heap, allowing for variable-size memory allocation.

  • The memory allocated with malloc must be explicitly freed with free() to avoid memory leaks.

Add your answer
Frequently asked in

Q45. 2. Difference between structure and union

Ans.

Structure is a collection of variables of different data types while union is a collection of variables of same data type.

  • Structure allocates memory for all its variables while union allocates memory for only one variable at a time.

  • Structure is used when we want to store different types of data while union is used when we want to store only one type of data at a time.

  • Structure is accessed using dot (.) operator while union is accessed using arrow (->) operator.

  • Example of stru...read more

Add your answer
Frequently asked in

Q46. Write C program in java

Ans.

It is not possible to write a C program in Java as they are two different programming languages.

  • C and Java are different programming languages with different syntax and features.

  • C programs use C-specific libraries and functions, while Java programs use Java-specific libraries and functions.

  • To write a C program, you need to use a C compiler, while to write a Java program, you need a Java compiler.

Add your answer
Frequently asked in

Q47. What is C programing language?

Ans.

C programming language is a versatile and widely-used language for developing system software and applications.

  • C is a procedural programming language

  • It is known for its efficiency and flexibility

  • C is used for developing operating systems, compilers, and embedded systems

View 1 answer
Frequently asked in

Q48. How do you rate in C?

Ans.

I rate myself as proficient in C programming language.

  • I have extensive experience in writing C code for various projects.

  • I am familiar with the syntax and semantics of the language.

  • I have a good understanding of memory management and pointers in C.

  • I have worked on optimizing C code for performance.

  • I have also mentored junior developers in C programming.

  • Overall, I am confident in my ability to write efficient and maintainable C code.

Add your answer

Q49. What is difference between printf and scanf

Ans.

printf is used to print output to the console while scanf is used to read input from the console.

  • printf is used to display output on the console

  • scanf is used to read input from the console

  • printf uses format specifiers to format output

  • scanf uses format specifiers to read input

  • printf returns the number of characters printed

  • scanf returns the number of input items successfully matched and assigned

Add your answer

Q50. Whats the maximum memory you can allocate with malloc()

Ans.

The maximum memory that can be allocated with malloc() depends on the system's available memory and the size of the largest contiguous block of memory.

  • The maximum memory that can be allocated is limited by the system's available memory.

  • The size of the largest contiguous block of memory also affects the maximum memory that can be allocated.

  • malloc() returns a null pointer if the requested memory cannot be allocated.

Add your answer

Q51. Wrote a code to retrieve file in C

Ans.

Code to retrieve a file in C

  • Use the fopen() function to open the file

  • Use the fread() function to read the contents of the file

  • Use the fclose() function to close the file

View 1 answer
Frequently asked in

Q52. Storage classes explain all the storage classes in c.

Ans.

Storage classes in C define the scope and lifetime of variables.

  • auto: default storage class for local variables

  • register: stores variables in CPU registers for faster access

  • static: retains value between function calls

  • extern: used to access global variables across multiple files

Add your answer
Frequently asked in

Q53. Do you know C language? If yes then write a program to print numbers from 1 to 10 excluding 5

Ans.

Yes, I know C language. Here's a program to print numbers from 1 to 10 excluding 5.

  • Use a loop to iterate from 1 to 10

  • Inside the loop, check if the current number is equal to 5

  • If it is not equal to 5, print the number

Add your answer
Frequently asked in

Q54. What are the data types in c language?

Ans.

C language has basic data types like int, char, float, double, void, and derived data types like arrays, pointers, and structures.

  • Basic data types include int, char, float, double, and void

  • Derived data types include arrays, pointers, and structures

  • Arrays can be of any basic data type

  • Pointers are used to store memory addresses

  • Structures are used to group related data of different data types

Add your answer

Q55. Explain C language to a non technical person?

Ans.

C is a programming language used to create software and operating systems.

  • C is a low-level language that allows direct access to computer hardware.

  • It is used to create efficient and fast programs.

  • C is the foundation for many other programming languages such as C++, Java, and Python.

  • Examples of C programs include operating systems, device drivers, and video games.

Add your answer

Q56. What is a latest embedded C programming?

Ans.

Latest embedded C programming includes features like dynamic memory allocation, multi-threading, and object-oriented programming.

  • Dynamic memory allocation allows for more efficient use of memory

  • Multi-threading enables concurrent execution of multiple tasks

  • Object-oriented programming allows for better code organization and reusability

Add your answer
Frequently asked in

Q57. If you are not having a sizeof operator in C, how will you get to know the size of an int ?

Ans.

Use the sizeof operator on a variable of type int to get its size.

  • Use sizeof operator on a variable of type int

  • Size of int is typically 4 bytes

  • Size may vary depending on the system architecture

Add your answer
Frequently asked in

Q58. Implement memcopy in C

Ans.

Implementing memcopy in C

  • Use a loop to copy each byte from the source to the destination

  • Handle overlapping memory regions correctly

  • Return a pointer to the destination

  • Ensure proper null termination for string copies

Add your answer
Frequently asked in

Q59. If len is the length of the string and num is the number of > characters printed on the screen > Give the relation between num and len. > > void abc (char *s){ > if(s[0]=='�') > return; > > abc(s+1); > abc(s+1)...

read more
Ans.

Relation between num and len in a given code snippet

  • The code recursively calls the function abc() twice for each character in the string

  • The printf() statement prints each character once

  • The number of '>' characters printed on the screen is equal to num

  • The length of the string is equal to len

  • The relation between num and len is num = 2^len - 1

Add your answer

Q60. Explain any program in C

Ans.

A program in C is a set of instructions written in the C programming language to perform a specific task.

  • C programs are written using a combination of variables, data types, control structures, and functions.

  • They are compiled into machine code and executed by a computer.

  • C programs can be used for various purposes such as mathematical calculations, data processing, system programming, etc.

  • Example: A simple C program to calculate the sum of two numbers:

  • ```c #include int main()...read more

Add your answer
Frequently asked in

Q61. To define file in Dynamic mode.

Ans.

Dynamic mode file is a file that is created and modified during runtime.

  • Dynamic mode files are created and modified during runtime

  • They are not stored on disk, but in memory

  • Examples include temporary files and buffers

Add your answer
Frequently asked in

Q62. Write a .small C code

Ans.

A C code that prints out the elements of an array of strings.

  • Declare an array of strings

  • Use a loop to iterate through the array

  • Print out each element

Add your answer
Frequently asked in

Q63. What is your c language ?

Ans.

C language is a high-level programming language used for system programming and developing applications.

  • C is a compiled language

  • It is used for developing operating systems, device drivers, and other system software

  • C is also used for developing desktop applications, games, and mobile apps

  • It is a structured programming language with a rich set of built-in functions and operators

  • C is known for its efficiency and performance

View 1 answer

Q64. What are control statements in c ?

Ans.

Control statements are used to control the flow of execution in a program.

  • There are three types of control statements in C: decision-making statements, loop statements, and jump statements.

  • Decision-making statements include if-else and switch statements.

  • Loop statements include for, while, and do-while loops.

  • Jump statements include break, continue, and goto statements.

  • Control statements are used to make a program more efficient and flexible.

  • Examples of control statements in C ...read more

Add your answer

Q65. 3.What is storage classes.

Ans.

Storage classes are keywords in C programming that define the scope and lifetime of variables.

  • There are four storage classes in C: auto, register, static, and extern.

  • Auto variables are local to a function and have a default value of garbage.

  • Register variables are stored in CPU registers for faster access.

  • Static variables retain their value between function calls.

  • Extern variables are declared outside of any function and can be accessed by other files.

  • Storage classes can affect...read more

Add your answer

Q66. What does preprocessor do in c?

Ans.

Preprocessor in C is a tool that processes source code before compilation.

  • It performs macro substitution

  • It includes header files

  • It conditionally compiles code

  • It defines constants and symbols

  • It removes comments

  • Examples of preprocessor directives are #include, #define, #ifdef, #ifndef, #endif

  • Preprocessor directives start with a # symbol

Add your answer

Q67. What is a function pointer and volatile type in c

Ans.

A function pointer is a variable that stores the address of a function. Volatile type is used to declare variables that can be modified by external factors.

  • Function pointers are used to pass functions as arguments to other functions.

  • Volatile type is used when a variable's value can be changed unexpectedly by external factors.

  • Function pointers can be used to implement callbacks or event handling mechanisms.

  • Volatile type is commonly used in embedded systems programming.

Add your answer
Frequently asked in

Q68. Explain the difference between Structure, union in C programming?

Ans.

Structure is a user-defined data type that groups related data members, while union is a data type that allows storing different data types in the same memory location.

  • Structures are used to group related data members of different data types, while unions are used to store different data types in the same memory location.

  • Structures allocate memory for each data member, while unions allocate memory for the largest data member.

  • Structures are accessed using the dot operator, whi...read more

Add your answer

Q69. What is data type in c language

Ans.

Data type in C language defines the type of data that a variable can hold.

  • C language has built-in data types like int, float, char, etc.

  • Data types determine the size and layout of variables in memory.

  • They also define the operations that can be performed on the variables.

  • For example, int can store whole numbers, float can store decimal numbers, and char can store single characters.

View 1 answer

Q70. How memory allocation is done in c

Ans.

Memory allocation in C is done using functions like malloc, calloc, realloc and free.

  • malloc function is used to allocate a block of memory of specified size

  • calloc function is used to allocate a block of memory and initialize it to zero

  • realloc function is used to change the size of previously allocated memory block

  • free function is used to deallocate the memory previously allocated using malloc, calloc or realloc

  • Memory allocation can also be done statically using arrays or dyna...read more

Add your answer
Frequently asked in

Q71. 1. What is structured, pointer, array , union

Ans.

Structured, pointer, array, and union are all data types in C programming language.

  • Structured data type is a collection of variables of different data types under a single name.

  • Pointer is a variable that stores the memory address of another variable.

  • Array is a collection of similar data types stored in contiguous memory locations.

  • Union is a special data type that allows storing different data types in the same memory location.

  • Example: struct employee { char name[20]; int age;...read more

Add your answer

Q72. Rate your C Coding out of 5

Ans.

I would rate my C coding skills as 4 out of 5.

  • Proficient in writing efficient and clean C code

  • Experience in developing complex algorithms and data structures

  • Familiar with low-level programming and memory management

  • Able to debug and optimize code for performance

  • Examples: Implemented a sorting algorithm, optimized memory usage in a large-scale project

View 1 answer
Frequently asked in
Q73. What is the use of a function pointer in C?
Ans.

Function pointers in C are used to store the address of functions, allowing for dynamic function calls and callbacks.

  • Function pointers can be used to implement callbacks in event-driven programming.

  • They can be used to switch between different functions at runtime.

  • Function pointers are commonly used in implementing data structures like function pointers in an array of function pointers.

  • Example: void (*funcPtr)(int) = &someFunction; funcPtr(5);

View 1 answer
Frequently asked in

Q74. How to invoke the xml file using LibXML?

Ans.

To invoke an XML file using LibXML, use the xmlReadFile() function.

  • Include the libxml/parser.h header file.

  • Use the xmlReadFile() function to read the XML file and create a xmlDocPtr object.

  • Use the xmlDocGetRootElement() function to get the root element of the XML document.

  • Use the xmlNodeGetContent() function to get the content of a node.

  • Use the xmlFreeDoc() function to free the memory allocated for the xmlDocPtr object.

  • Use the xmlCleanupParser() function to free the memory al...read more

Add your answer

Q75. what comes to your mind when I tell you about C language?

Ans.

C language is a popular programming language known for its efficiency and low-level programming capabilities.

  • C language is a general-purpose programming language.

  • It was developed by Dennis Ritchie at Bell Labs in the early 1970s.

  • C language is widely used for system programming and embedded systems.

  • It provides low-level access to memory and hardware.

  • C language is known for its efficiency and performance.

  • It is the foundation for many other programming languages like C++, Java, ...read more

Add your answer
Frequently asked in

Q76. Calculate size of variable without library function

Ans.

Calculate size of variable without library function

  • Use the sizeof operator to calculate the size of a variable

  • Multiply the size by the number of elements if it's an array

  • Size of a struct is the sum of sizes of its members

  • Size of a union is the size of its largest member

  • Size of a pointer is platform-dependent

Add your answer

Q77. 1.Difference between structure and union

Ans.

Structure and union are both used to store different types of data, but they differ in memory allocation and usage.

  • Structure is a user-defined data type that allows storing different types of data in a single variable.

  • Union is also a user-defined data type that allows storing different types of data in a single variable, but it shares the same memory location for all its members.

  • In a structure, each member has its own memory location, and the total memory allocated is the sum...read more

View 1 answer

Q78. Implement strstr() Function in C Problem Statement

Given two strings A and B, find the index of the first occurrence of A in B. If A is not present in B, return -1.

Example:

Input:
A = "bc", B = "abcddbc"
Outpu...read more
Ans.

Implement the strstr() function in C to find the index of the first occurrence of one string in another.

  • Iterate through the main string and check if the substring matches at each position.

  • Return the index if a match is found, else return -1.

  • Handle edge cases like empty strings or when the substring is longer than the main string.

Add your answer
Frequently asked in

Q79. Explain different storage classes in C.Explain static storage class if used in your project.

Ans.

Different storage classes in C and explanation of static storage class.

  • Storage classes in C are auto, register, static and extern.

  • Auto storage class is default and variables are stored in stack memory.

  • Register storage class is used for variables that need to be accessed quickly and are stored in CPU registers.

  • Static storage class is used for variables that retain their value even after function execution and are stored in data segment.

  • Static storage class can be used in a pro...read more

Add your answer
Frequently asked in

Q80. What is c language used for? What is it required?

Ans.

C language is a general-purpose programming language used for system programming, embedded systems, and game development.

  • C is used for developing operating systems, device drivers, and firmware.

  • It is required for programming microcontrollers and other embedded systems.

  • C is also used for game development and high-performance computing.

  • It is a low-level language that provides direct access to memory and hardware.

  • C is a popular language for competitive programming and algorithm ...read more

Add your answer

Q81. Write an API call in C

Ans.

API call in C

  • Include the necessary header files

  • Create a URL string with the required parameters

  • Use the curl library to make the API call

  • Handle the response data appropriately

Add your answer

Q82. What is storage class specifire?

Ans.

Storage class specifier is a keyword used in C programming language to define the scope and lifetime of a variable.

  • There are four storage class specifiers in C: auto, register, static, and extern.

  • Auto variables are created when a function is called and destroyed when the function returns.

  • Register variables are stored in CPU registers for faster access.

  • Static variables retain their value between function calls.

  • Extern variables are declared outside of any function and can be ac...read more

Add your answer

Q83. How would you rate your C programming skill on a level of 0-5?

Ans.

4

  • Extensive experience in C programming

  • Proficient in writing efficient and optimized code

  • Familiar with memory management and pointers

  • Comfortable with low-level programming and system-level development

Add your answer
Frequently asked in

Q84. When was c language developed?

Ans.

C language was developed in 1972.

  • Developed by Dennis Ritchie at Bell Labs.

  • First appeared in 1972.

  • Influential in the development of many other programming languages like C++, Java, and Python.

View 1 answer

Q85. diff b/w structure and union

Ans.

Structure is a collection of variables of different data types while union is a collection of variables of same data type.

  • Structure allocates memory for all its variables while union allocates memory for only one variable at a time.

  • Structure is used when we want to store different types of data while union is used when we want to store only one type of data.

  • Structure is accessed using dot operator while union is accessed using arrow operator.

  • Example of structure: struct stude...read more

Add your answer
Frequently asked in

Q86. What is printf() and scanf()?

Ans.

printf() and scanf() are functions in the C programming language used for input and output operations.

  • printf() is used to print formatted output to the console.

  • scanf() is used to read formatted input from the console.

  • Both functions are part of the standard input/output library in C.

  • printf() uses format specifiers to control the output format.

  • scanf() uses format specifiers to match and extract input values.

Add your answer

Q87. Can you explain your C program of Programming test?

Ans.

The C program for the Programming test involves solving a specific problem using the C programming language.

  • The program likely includes functions, loops, and conditional statements to solve the problem.

  • It may involve working with arrays, strings, or other data structures.

  • Error handling and input validation are important aspects of the program.

  • Example: Implementing a sorting algorithm in C to sort an array of integers.

Add your answer
Frequently asked in

Q88. #define Vs typedef

Ans.

Both #define and typedef are used for defining aliases for data types in C/C++.

  • Use #define to define constants or macros.

  • Use typedef to define new data types.

  • Syntax for #define: #define identifier value

  • Syntax for typedef: typedef existing_type new_type_name;

  • Example of #define: #define PI 3.14159

  • Example of typedef: typedef int myInt;

Add your answer
Frequently asked in

Q89. main ( ) { unsigned int i=3; while( i >=0) printf( "%d", i--); } How many times will the printf stmt be executed? a) 0 b) 3 c) 4 d) infinite Ans: I think the answer is infinite, because 'i' is an unsigned integ...

read more
Ans.

The printf statement will be executed 4 times.

  • The initial value of 'i' is 3.

  • In each iteration of the while loop, 'i' is decremented by 1.

  • The loop will continue until 'i' becomes less than 0.

  • Therefore, the printf statement will be executed 4 times.

Add your answer

Q90. What is the role of printf?

Ans.

printf is a function in C programming language used to print output on the console.

  • printf is used to display output on the console

  • It can be used to print variables, strings, and expressions

  • It uses format specifiers like %d, %f, %s to format the output

  • Example: printf("The value of x is %d", x);

Add your answer
Frequently asked in

Q91. what were difficulties you encountered in learning c?

Ans.

I encountered difficulties in learning C due to its complex syntax and memory management.

  • Understanding pointers and memory allocation

  • Dealing with segmentation faults and memory leaks

  • Mastering the syntax and usage of C libraries

  • Debugging and troubleshooting C programs

Add your answer

Q92. What is the difference between the two declarations? int p=*(int*)i; int p=*(int*)&i;

Ans.

The first declaration casts i to int pointer and dereferences it, while the second declaration casts the address of i to int pointer and dereferences it.

  • The first declaration assumes i is already an int pointer.

  • The second declaration takes the address of i and casts it to an int pointer.

  • The first declaration may cause a segmentation fault if i is not an int pointer.

  • The second declaration may cause unexpected behavior if i is not aligned to an int.

  • Example: int i = 42; int p = ...read more

Add your answer

Q93. do you have knowledge on c

Ans.

Yes, I have knowledge on C programming language.

  • I have experience in writing programs in C language.

  • I am familiar with the syntax and semantics of C language.

  • I have worked on projects that involved C language such as developing embedded systems.

  • I have knowledge of data types, control structures, functions, pointers, arrays, and structures in C language.

Add your answer
Frequently asked in

Q94. Implement packet in C

Ans.

Implementing packet in C involves creating a data structure to hold packet information and functions to manipulate it.

  • Create a struct to hold packet information such as source and destination addresses, payload, and checksum

  • Write functions to initialize, read, and write packet data

  • Use network byte order for multi-byte fields to ensure compatibility across different architectures

Add your answer

Q95. how is c coded

Ans.

C is a procedural programming language that is compiled and used to create software applications and operating systems.

  • C code is written in a text editor and saved with a .c extension

  • It uses a set of predefined keywords, data types, and functions

  • C code is compiled into machine code using a compiler

  • C code can be used for low-level programming, system programming, and embedded programming

Add your answer

Q96. What are variables in C?

Ans.

Variables in C are containers that hold data values and can be manipulated throughout the program.

  • Variables must be declared before use

  • They can hold different types of data such as integers, floats, and characters

  • Their values can be changed throughout the program

  • They can be used in mathematical operations

  • Examples: int age = 25; float price = 10.99; char letter = 'a';

Add your answer
Frequently asked in

Q97. there three files f1.c, f2.c, f3.c.. in f1.c int a is declared, in f2.c static int b are declared.. what are the variables that can be accessed from files f1.c and f2.c in f3.c ... If variable 'a' has to be acc...

read more
Ans.

Variables accessible from f1.c and f2.c in f3.c. 'a' needs to be declared as extern to be accessed.

  • Variables declared as static in f2.c can only be accessed within f2.c

  • Variables declared in f1.c can be accessed in f3.c by declaring them as extern

  • Variables declared in f3.c cannot be accessed in f1.c or f2.c

Add your answer
Frequently asked in

Q98. Implement the malloc() and free() operations. Give the strategy for implementation, no coding

Ans.

The malloc() and free() operations are used for dynamic memory allocation and deallocation in programming.

  • malloc() is used to allocate a block of memory of a specified size.

  • free() is used to deallocate the memory previously allocated by malloc().

  • The strategy for implementation involves managing a data structure to keep track of allocated and free memory blocks.

  • One common strategy is to use a linked list to maintain the blocks of memory.

  • When malloc() is called, it searches the...read more

Add your answer

Q99. What is malloc calloc?

Ans.

malloc and calloc are functions used in C programming language to dynamically allocate memory.

  • malloc stands for memory allocation and is used to allocate a block of memory of specified size.

  • calloc stands for contiguous allocation and is used to allocate multiple blocks of memory of specified size.

  • Both functions return a pointer to the first byte of the allocated memory.

  • It is important to free the allocated memory using the free() function to avoid memory leaks.

Add your answer
Frequently asked in

Q100. What is static storage class

Ans.

Static storage class is used to declare variables that have a lifetime throughout the program execution.

  • Variables declared with static storage class are initialized only once and retain their value between function calls.

  • They have a default value of 0 if not initialized explicitly.

  • Static functions and variables are only visible within the file they are declared in.

  • Static variables can be used to count the number of times a function is called or to cache values for future use.

Add your answer
1
2
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.7
 • 10.4k Interviews
3.6
 • 7.5k Interviews
3.7
 • 5.6k Interviews
3.8
 • 5.6k Interviews
3.7
 • 4.7k Interviews
3.5
 • 3.8k Interviews
3.5
 • 3.8k Interviews
4.1
 • 370 Interviews
View all
C Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter