Dell Boomi Frequently Asked C Language Interview Questions

Dell Boomi Most Frequently Asked C Language Interview Questions Answers

Mention The Levels Of Pointers Can You Have?

The

depends on what you mean by “levels of pointers.” If you mean “How many levels of indirection can you have in a single declaration?” the

is “At least 12.”

int i = 0;
int *ip01 = & i;
int **ip02 = & ip01;
int ***ip03 = & ip02;
int ****ip04 = & ip03;
int *****ip05 = & ip04;
int ******ip06 = & ip05;
int *******ip07 = & ip06;
int ********ip08 = & ip07;
int *********ip09 = & ip08;
int **********ip10 = & ip09;
int ***********ip11 = & ip10;
int ************ip12 = & ip11;
************ip12 = 1; /* i = 1 */
The ANSI C standard says all compilers must handle at least 12 levels. Your compiler might support more.

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.

How Do You Print Only Part Of A String?

/* Use printf () to print the first 11 characters of source_str. */

printf (“First 11 characters: ‘%11.11s’n”, source_str);

How To Convert A String To A Number?

The standard C library provides several functions for converting strings to numbers of all formats (integers, longs, floats, and so on) and vice versa.

The following functions can be used to convert strings to numbers
Function Name Purpose

atof():  Converts a string to a double-precision floating-point value.
atoi():  Converts a string to an integer.
atol():  Converts a string to a long integer.

How To 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

iota():    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.
The following functions can be used to convert floating-point values to strings
Function Name Purpose

ecvt() :   Converts a double-precision floating-point value to a string without an embedded decimal point.
fcvt():      Same as ecvt(), but forces the precision to a specified number of digits.
gcvt():     Converts a double-precision floating-point value to a string with an embedded decimal point.
strtod():   Converts a string to a double-precision floating-point value and reports any “leftover” numbers that could not be converted.
strtol():    Converts a string to a long integer and reports any “leftover” numbers that could not be converted.
strtoul():  Converts a string to an unsigned long integer and reports any “leftover” numbers that could not be converted.
Dell Boomi Most Frequently Asked C Language Interview Questions Answers
Dell Boomi Most Frequently Asked C Language Interview Questions Answers

Differentiate Between #include And #include "file"?

When writing your C program, you can include files in two ways. The first way is to surround the file you want to include with the angled brackets < and >. This method of inclusion tells the preprocessor to look for the file in the predefined default location. This predefined default location is often an INCLUDE environment variable that denotes the path to your include files. For instance, given the INCLUDE variable

INCLUDE=C:\COMPILER\INCLUDE;S:\SOURCE\HEADERS;
using the #include version of file inclusion, the compiler first checks the C:\COMPILER\INCLUDE directory for the specified file. If the file is not found there, the compiler then checks the S:\SOURCE\HEADERS directory. If the file is still not found, the preprocessor checks the current directory.

The second way to include files is to surround the file you want to include with double quotation marks. This method of inclusion tells the preprocessor to look for the file in the current directory first, then look for it in the predefined locations you have set up. Using the #include “file” version of file inclusion and applying it to the preceding example, the preprocessor first checks the current directory for the specified file. If the file is not found in the current directory, the C:COMPILERINCLUDE directory is searched. If the file is still not found, the preprocessor checks the S:SOURCEHEADERS directory.

The #include method of file inclusion is often used to include standard headers such as stdio.h or stdlib.h. This is because these headers are rarely (if ever) modified, and they should always be read from your compiler’s standard include file directory.

The #include “file” method of file inclusion is often used to include nonstandard header files that you have created for use in your program. This is because these headers are often modified in the current directory, and you will want the preprocessor to use your newly modified version of the header rather than the older, unmodified version.

Which Is Better To Use A Macro Or A Function?

The

depends on the situation you are writing code for. Macros have the distinct advantage of being more efficient (and faster) than functions, because their corresponding code is inserted directly into your source code at the point where the macro is called. There is no overhead involved in using a macro like there is in placing a call to a function. However, macros are generally small and cannot handle large, complex coding constructs. A function is more suited for this type of situation. Additionally, macros are expanded inline, which means that the code is replicated for each occurrence of a macro. Your code therefore could be somewhat larger when you use macros than if you were to use functions. Thus, the choice between using a macro and using a function is one of deciding between the tradeoff of faster program speed versus smaller program size. Generally, you should use macros to replace small, repeatable code sections, and you should use functions for larger coding tasks that might require several lines of code.

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.

Post a Comment

Previous Post Next Post