Functions in C Interview Questions & Answers - Learning Mode | |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
|
Functions in C Interview Questions & Answers - Learning ModeA function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions. You can divide up your code into separate functions. In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive. You can either use the built-in library functions or you can create your own functions. Functions that a programmer writes will generally require a prototype. |
|
Try Functions in C Interview Questions & Answers - Exam Mode | |
Functions in C Interview Questions & Answers - Learning Mode |
Try Functions in C Interview Questions & Answers - Exam Mode |
Question: How would you use the functions randomize()and random()?
Answer: |
Question: How to print a statement without using printf() in c?
Answer: using getchar() main() { int i; char c; for(i=0;i!=' ';i++) { c=getchar(); putchar(c,n); } getch(); } Source: CoolInterview.com |
Question: What is a static function?
Answer: A static function is a function whose scope is limited to the current source file. Scope refers to the visibility of a function or variable. If the function or variable is visible outside of the current source file, it is said to have global, or external, scope. If the function or variable is not visible outside of the current source file, it is said to have local, or static, scope. Source: CoolInterview.com |
Question: What are returned by printf(), scanf() functions,if they return anything means what are that? Answer: Return type of printf() and scanf() is integer. scanf() returns the no.of variables used and printf() returns the total no.of bytes. Source: CoolInterview.com |
Question: Is using exit() the same as using return?
Answer: No. The exit() function is used to exit your program and return control to the operating system. The return statement is used to return from a function and return control to the calling function. If you issue a return from the main() function, you are essentially returning control to the calling function, which is the operating system. In this case, the return statement and exit() function are similar. Source: CoolInterview.com |
Question: What are the advantages of the functions?
Answer: ?Debugging is easier<br><br>?It is easier to understand the logic involved in the program<br><br>?Testing is easier<br><br>?Recursive call is possible<br><br>?Irrelevant details in the user point of view are hidden in functions<br><br>?Functions are helpful in generalizing the program Source: CoolInterview.com |
Question: How do you use a pointer to a function?
Answer: The hardest part about using a pointer-to-function is declaring it. Consider an example. You want to create a pointer, pf, that points to the strcmp() function. The strcmp() function is declared in this way: int strcmp(const char *, const char * ) To set up pf to point to the strcmp() function, you want a declaration that looks just like the strcmp() function?s declaration, but that has *pf rather than strcmp: int (*pf)( const char *, const char * ); Aft Source: CoolInterview.com |
Question: What is the code for clrscr() function?
Answer: clrscr() is a function which creates a screenful of black dots which seems us to be clearing the screen or making a new screen. Source: CoolInterview.com |
Question: How do we get Square root of any number Without using sqrt() function? Answer: You can use a iterative method for example bisection #include <stdio.h> main() { int n; float eval=1.0,x1=0,x2=n,x; //trying to locate root between x1=0 and x2=n and giving a initial dummy value to eval x=(x1+x2)/2; printf("Enter value for n n n"); scanf("%d",&n); while((eval > 0.0001 )||( eval < -0.0001) ) { //you can change accuracy by changing 0.0001 to smaller value eval= x*x-n; printf(" eval = %f t",eval); //printf to keep track not n Source: CoolInterview.com |
Question: How would you use bsearch()function to search a name stored in array of pointers to string?
Answer: |
Question: How can send unlimited no of arguments to a function, eg printf function can take any no of arguments Answer: using va_list variables in stdarg.h headerfile Source: CoolInterview.com |
Question: What is an argument ? differentiate between formal arguments and actual arguments?
Answer: An argument is an entity used to pass the data from calling function to the called function. Formal arguments are the arguments available in the function definition.They are preceded by their own data types.Actual arguments are available in the function call. Source: CoolInterview.com |
Question: How to use floodfill() function and what is the use of kbhit?
Answer: Flood-fills a bounded region Declaration: void far floodfill(int x, int y, int border); Remarks: floodfill fills an enclosed area on bitmap devices. The area bounded by the color border is flooded with the current fill pattern and fill color. (x,y) is a "seed point". ? If the seed is within an enclosed area, the inside will be filled. ? If the seed is outside the enclosed area, the exterior will be filled. floodfill does not wor Source: CoolInterview.com |
Question: What is the output of void main() { int a = (1,2,3); printf("%d",a); } with reason. Answer: The answer is 3 The value which is last in the bracket is assigned to a(the variable).If it would have been any other value except 3,then it would have been assigned to 'a'. Source: CoolInterview.com |
Question: Write a program with out using main() function? Answer: #include<stdio.h> #define decode(s,t,u,m,p,e,d) m##s##u##t #define begin decode(a,n,i,m,a,t,e) int begin() { printf(" hello "); } Source: CoolInterview.com |
Question: Differentiate between a linker and linkage?
Answer: A linker converts an object code into an executable code by linking together the necessary build in functions. The form and place of declaration where the variable is declared in a program determine the linkage of variable. Source: CoolInterview.com |
Question: What is the difference between goto and longjmp() and setjmp()?
Answer: A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions implement a nonlocal, or far, jump of program execution. Generally, a jump in execution of any kind should be avoided because it is not considered good programming practice to use such statements as goto and longjmp in your program. A goto statement simply bypasses code in your program and jumps to a predefined position. To use the goto statement, you give it a labeled position t Source: CoolInterview.com |
Question: How argc and argv works in the following main function? main(int argc,char *argv[]) { int n,i=0; while(argv[1][i]!=' Answer: *****main can recieve its own arguments but in a preconditioned way: main (int argc, char **argv) { ............ }*****% a.out 1 my_input argc is 3 argv[0] = "a.out" argv[1]="1" argv[2]="my_input" Source: CoolInterview.com |
Question: What is a method?
Answer: Method is a way of doing something, especially a systematic way; implies an orderly logical arrangement (usually in steps). Source: CoolInterview.com |
Question: In c , main() is a function . and where is defined main() in c. bcz every function has three parts. 1>. decleration 2>. definition. 3>. calling Answer: Declaration is not needed if method is defined before calling.main() method is called by the OS when the program is run.So, it has only a definition.. Source: CoolInterview.com |
India News Network |