Top 150 C Interview Questions and Answers
Updated 12 Dec 2024
Q1. Write a code for the length of string without using strlen() function.
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
Q2. What is c code in java
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
Q3. Why is c++ better than C?
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
Q4. Draw the flow chart for the following C program
Flow chart for a C program
Identify the input and output
Determine the conditions and loops
Draw the flow chart accordingly
Q5. How can we Do Web development using C
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.
Q6. What is c and what is routing
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
Q7. Data structures through c language
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
Q8. What are storage classes in C?Explain
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.
C Jobs
Q9. What is the diff between c and c++
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
Q10. Write a C program that will COMPILE and RUN to reverse a string in-place
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
Q11. Difference between c,c++
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.
Q12. What are key features of static storage class?
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
Q13. c vs c++ diff
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.
Q14. Implement bit fields and explain with a piece of code
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
Q15. How many classes are there in C? Explain.
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.
Q16. Write the any coding in c language?
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
Q17. Explain a Storage classes
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.
Q18. Write a simple C program.
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;
Q19. How to find common elements from two arrays using C
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
Q20. What is c language? What is keyword in c language?
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.
Q21. write a program on structure.? and by using pointers how we declare structures.
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;
Q22. Does any libraries are required to perform c programming and what are they?
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
Q23. Write a program to implement strcmp
Program to implement strcmp
Use a loop to compare each character of the two strings
Return 0 if both strings are equal, -1 if s1
s2 Handle null and empty strings appropriately
Q24. What is the use of printf() and scanf() function?
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'.
Q25. What are storage class specifiers in c?
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
Q26. Do you know C Programming?
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.
Q27. What are features of C language ?
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
Q28. Which are the four storage classes in C
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
Q29. Write a C program and explain each line to me
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.
Q30. How can we start the program in c language?
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
Q31. Write the Test_and_Set program
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;
Q32. define structure and union in C
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
Q33. Difference between delete and free
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
Q34. What are static, volatile, const in C mean ?
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
Q35. why is main function required in c program
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 }
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 moreYes, 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
Q37. Explain whole process for Example.c file to Example.exe conversion
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
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
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.
Q39. Difference between arr and adr
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
Q40. Who is the founder of c language?
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.
Q41. What are the criteria for c program
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
Q42. What is static variable in C? with program
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.
Q43. Can I declare a structure called ‘a’ which contains a structure called ‘b’ and ‘b’ in turn contains ‘a’?
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.
Q44. What is the difference between into arr [5] and malloc (5*sizeof (int))
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.
Q45. 2. Difference between structure and union
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
Q46. Write C program in java
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.
Q47. What is C programing language?
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
Q48. How do you rate in C?
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.
Q49. What is difference between printf and scanf
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
Q50. Whats the maximum memory you can allocate with malloc()
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.
Q51. Wrote a code to retrieve file in C
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
Q52. Storage classes explain all the storage classes in c.
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
Q53. Do you know C language? If yes then write a program to print numbers from 1 to 10 excluding 5
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
Q54. What are the data types in c language?
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
Q55. Explain C language to a non technical person?
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.
Q56. What is a latest embedded C programming?
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
Q57. If you are not having a sizeof operator in C, how will you get to know the size of an int ?
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
Q58. Implement memcopy in C
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
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 moreRelation 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
Q60. Explain any program in C
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
Q61. To define file in Dynamic mode.
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
Q62. Write a .small C code
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
Q63. What is your c language ?
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
Q64. What are control statements in c ?
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
Q65. 3.What is storage classes.
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
Q66. What does preprocessor do in c?
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
Q67. What is a function pointer and volatile type in c
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.
Q68. Explain the difference between Structure, union in C programming?
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
Q69. What is data type in c language
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.
Q70. How memory allocation is done in c
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
Q71. 1. What is structured, pointer, array , union
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
Q72. Rate your C Coding out of 5
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
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);
Q74. How to invoke the xml file using LibXML?
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
Q75. what comes to your mind when I tell you about C language?
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
Q76. Calculate size of variable without library function
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
Q77. 1.Difference between structure and union
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
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
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.
Q79. Explain different storage classes in C.Explain static storage class if used in your project.
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
Q80. What is c language used for? What is it required?
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
Q81. Write an API call in C
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
Q82. What is storage class specifire?
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
Q83. How would you rate your C programming skill on a level of 0-5?
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
Q84. When was c language developed?
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.
Q85. diff b/w structure and union
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
Q86. What is printf() and scanf()?
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.
Q87. Can you explain your C program of Programming test?
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.
Q88. #define Vs typedef
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;
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 moreThe 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.
Q90. What is the role of printf?
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);
Q91. what were difficulties you encountered in learning c?
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
Q92. What is the difference between the two declarations? int p=*(int*)i; int p=*(int*)&i;
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
Q93. do you have knowledge on c
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.
Q94. Implement packet in C
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
Q95. how is c coded
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
Q96. What are variables in C?
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';
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 moreVariables 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
Q98. Implement the malloc() and free() operations. Give the strategy for implementation, no coding
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
Q99. What is malloc calloc?
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.
Q100. What is static storage class
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.
Top Interview Questions for Related Skills
Interview Questions of C Related Designations
Interview experiences of popular companies
Reviews
Interviews
Salaries
Users/Month