C Programming Interview Questions and Answers-7

Q: – Write a program to reverse a string with out using any array? #include<stdio.h> int main() { char *str=”Mahesh”; char *ptr=str+strlen(str); while(ptr>=str) { printf(“%c”,*ptr); ptr–; } } Q: – How do you find IP adress of ur system? ipconfig – in windows cmd mode. ifconfig -a in linux and hostname|nslookup in linux. Q: – What is the output of this program? #include<stdio.h> void Allocate(char *str, int size) { str =(char *)malloc(size); } int main() { char *str; Allocate(str, 20); strcpy(str, “HCL”); strcat(str, “Technologies”); printf(“%sn”,str); } Answer:Run time error(segmentation fault). Reason: in function Allocate, we have allocated memory by using … Click here to continue reading.

C Programming Interview Questions and Answers-6

Q: – Explain “method”? A Method is a programmed procedure. It is defined as part of a class also included in any object of that class. Class can have more than one methods. It can be re-used in multiple objects. Q: – What is the output of the bellow program? segmentation fault.because we are trying to read/assign character into const string. #include<stdio.h> main() { char *ptr=”HELLO”; ptr[0]=’A'; printf(“%s”,ptr); } Q: – Write a program to display number from the bellow string? char *ptr=”HELLO57hai” #include<stdio.h> int main() { char *ptr=”HELLO57hai”; while(*ptr) { if(*ptr<’A') printf(“%c”,*ptr); ptr++; } } Q: – what are … Click here to continue reading.

C Programming Interview Questions and Answers-5

Q: – How do you remove a macro name? By using the #undef directive with a macro name, that macro name can be removed, or “undefined.” Q: – Why do you need the #endif directive? The #endif directive is used with an #if, #ifdef, or #ifndef directives because statements under the control of a conditional preprocessor directive are not enclosed in braces ({ and }). Therefore, #endif must be used to mark the end of the block of statements. Q: – Can the conditional expression following the #if directive be an arithmetic expression? Yes Q: – What is the difference … Click here to continue reading.

C Programming Interview Questions and Answers-4

Q: – Why do we need function prototypes? With the help of a function prototype, the compiler can automatically perform type checking on the definition of the function, which saves you time in debugging the program. Q: – Can a function return a pointer? Yes Q: – Why do you need to use arrays of pointers? It is convenient to use an array of pointers to point to a set of character strings so that you can access any one of the strings referenced by a corresponding pointer in the array. Q: – What does it mean if the malloc() … Click here to continue reading.

C Programming Interview Questions and Answers-3

Q: – What are stdin, stdout, and stderr? In C, a file is treated as a series of bytes that is called file stream. stdin, stdout, and stderr are all pre-opened file streams. stdin is the standard input for reading; stdout is the standard output for writing; stderr is the standard error for outputting error messages. Q: – What value is yielded by a relational expression? A relational expression evaluates to either 0 or 1. If the relation indicated by a relational operator in an expression is true, the expression evaluates to 1; otherwise, the expression evaluates to 0. Q: … Click here to continue reading.