The ones who are crazy enough to think they can change the world are the ones who do.- Steve Jobs
In most of the MNC interview questions such as in ZOHO interview question, IVTL Infoview interview questions, Amazon interview questions, GOOGLE interview questions, Infosys interview questions and even in Voonik interview questions, We come across several Tricky C Questions about which 2:5 of the questions are from Functions in c. Solving that kind of tricky C questions is not an easy task for all C programmers. We need more practices to solve it with ease. So we provide 25+ interesting C questions in Functions to make your MNC interview very easy.
11. What will be the output of the C program?
#include<stdio.h> int main() { char arr[] = "function\0"; int num = strlen(a); printf("Length of function is %d", num); return 0; }
Option: D
Here the char arrray arr will hold the initialized string "function\0", whose length will be counted from 0 till the null character. Hence num holds the integer value 8.
12. What will be the output of the C program?
#include<stdio.h> void abc(); int *ptr; int main() { int i, *p = &i; abc(); return 0; } void abc() { int i = 0; ptr = &i; ptr++; *ptr = 3; printf("\nFunction in C %d", i); }
Option: A
*ptr = 3 won't affect the value in a variable i. Because ptr is post increment to the next address of i before declaring *ptr = 3.
Thus outputted Function in C 0.
13. What will be the output of the C program by considering 'b' as a User input?
#include<stdio.h> char normal[15] = "Ambulance"; char accident[15]; int main() { swab(normal, accident, strlen(normal +1)); printf ("%s\n", normal); return 0; }
Option: C
swab is a special type of function in c, which is capable of swapping two text consecutively in a string.
It must to noted that swab function won't display the last odd charater as we saw here "e" is missing in a string "Ambulance"
14. What will be the output of the C program?
#include<stdio.h> void ptr(char**); int main() { char *argv[] = { "abc", "def", "ghi", "jkl", "mno", "pqr" }; ptr(argv); return 0; } void ptr(char **p) { char *t; t = (p += sizeof(int))[-1]; printf("%s\n", t); }
Option: B
Here we used pointer array to store a strings ie ) array of string using pointer variable.
ptr() is a valid function which passes the address of first element in an array *argv[].
In ptr() function we get the value p = "abc"
now t = (p = p + sizeof(int))[-1];
t = p = ((address of abc) + 4)[-1]
t = p = (address of mno)[-1]
t = p = address of jkl.
t = jkl as t is single pointer character type
15. What will be the output of the C program?
#include<stdio.h> int recursive(int i) { static int count = 0; count = count + i; return count; } int main() { int i, j; for (i = 0; i <= 5; i++) j = recursive(i); printf("%d\n", j); return 0; }
Option: C
static int count = 0 is only for the first time od iteration because its static.
count = count + i;
count = 0 + 0;
count = 0;
count = count + 1;
count = 0 + 1;
count = 0;
count = count + 2;
count = 1 + 2;
count = 3;
count = count + 3;
count = 3 + 3;
count = 6;
count = count + 4;
count = 6 + 4;
count = 10;
count = count + 5;
count = 10 + 5;
count = 15;
We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.
© Copyright 2019