-
How are portions of a program disabled in demo versions?
If you are distributing a demo version of your program, the preprocessor can be used to enable or disable portions of your program. The following portion of code shows how this task is accomplished, using the preprocessor directives #if and #endif: int save_document(char* doc_name) { #if DEMO_VERSION printf(“Sorry! You can’t save documents using the DEMO version of this program!n”); return(0); #endif...
-
Is NULL always defined as 0?
NULL is defined as either 0 or (void*)0. These values are almost identical; either a literal zero or a void pointer is converted automatically to any kind of pointer, as necessary, whenever a pointer is needed (although the compiler can’t always tell when a pointer is needed).
-
Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name?
It’s easier for a C compiler to generate good code for pointers than for subscripts.
-
What is the benefit of using #define to declare a constant?
Using the #define method of declaring a constant enables you to declare a constant in one place and use it throughout your program. This helps make your programs more maintainable, because you need to maintain only the #define statement and not several instances of individual constants throughout your program. For instance, if your program used the value of pi (approximately 3.14159) several...
-
What is the quickest sorting method to use?
The answer depends on what you mean by quickest. For most sorting problems, it just doesn’t matter how quick the sort is because it is done infrequently or other operations take significantly more time anyway. Even in cases in which sorting speed is of the essence, there is no one answer. It depends on not only the size and nature of the data, but also the likely order. No algorithm is best in all...
-
When should a type cast not be used?
A type cast should not be used to override a const or volatile declaration. Overriding these type modifiers can cause the program to fail to run correctly. A type cast should not be used to turn a pointer to one type of structure or data type into another. In the rare events in which this action is beneficial, using a union to hold the values makes the programmer’s intentions clearer.
-
When should a type cast be used?
There are two situations in which to use a type cast. The first use is to change the type of an operand to an arithmetic operation so that the operation will be performed properly. The second case is to cast pointer types to and from void * in order to interface with functions that expect or return void pointers. For example, the following line type casts the return value of the call to malloc()...
-
-
-
According to ANSI specifications which is the correct way of declaring main() when it receives command line arguments?
A) main(int argc, char *argv[]) B) main(argc,argv) int argc; char *argv[];C) main() {int argc; char *argv[]; }D) None of the above
-
-
-
-
-
-
How can I convert a number to a string?
The standard C library provides several functions for converting numbers of all formats (integers, longs, floats, and so on) to strings and vice versa The following functions can be used to convert integers to strings: Function Name Purpose itoa() Converts an integer value to a string. ltoa() Converts a long integer value to a string. ultoa() Converts an unsigned long integer value to a string....
-
Find Number of Occurrences
How will you find the number of occurrences of a particular string in the given input string?
-
-
Memory Allocation
we say stack is allocated to the local variables ,formal arguments and return addresses of a function for manipulating function calls?but the question arises when does the stack allocation to above things take place?at compile time or run time.And by the way what about automatic memory allocation.what is it?
-
A Program that does nothing
Write a program in C that does nothing not even takes memory?
C Interview Questions
Ans