Home > Interview > Technical Interview > C Programming

C Programming

Standard Library Functions

Why should I use standard library functions instead of writing my own? The standard library functions have three advantages: they work, they’re efficient, and they’re portable. They work: Your compiler vendor probably got them right. More important, the vendor is likely to have done a thorough test to prove they’re …

Read More »

Pointers

What is indirection? If you declare a variable, its name is a direct reference to its value. If you have a pointer to a variable, or any other object in memory, you have an indirect reference to its value. If p is a pointer, the value of p is the …

Read More »

Strings

What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used? The strcpy() function is designed to work exclusively with strings. It copies each byte of the source string to the destination string and stops when the terminating null character (\0) has …

Read More »

Functions

When should I declare a function? Functions that are used only in the current source file should be declared as static, and the function’s declaration should appear in the current source file along with the definition of the function. Functions used outside of the current source file should have their …

Read More »

Variables and Data Storage

Where in memory are my variables stored? Variables can be stored in several places in memory, depending on their lifetime. Variables that are defined outside any function (whether of global or file static scope), and variables that are defined inside a function as static variables, exist for the lifetime of …

Read More »

Data Files

If errno contains a nonzero number, is there an error? The global variable errno is used by many standard C library functions to pass back to your program an error code that denotes specifically which error occurred. However, your program should not check the value of errno to determine whether …

Read More »

Arrays

Do array subscripts always start with zero? Yes. If you have an array a[MAX] (in which MAX is some value known at compile time), the first element isa[0], and the last element is a[MAX-1]. This arrangement is different from what you would find in some other languages. In some languages, …

Read More »

Preprocessors

What is a macro, and how do you use it? A macro is a preprocessor directive that provides a mechanism for token replacement in your source code. Macros are created by using the #define statement. Here is an example of a macro: #define VERSION_STAMP “1.02” The macro being defined in …

Read More »