You are on page 1of 3

VIVA QUESTIONS-C PROGRAMMING

1. What is the output of following code?

char letter = 'Z';


printf("The ASCII value of %c is %d\n", letter, letter);

char ch = 'A';
printf("%d\n", ch);

char str[] = "Hello, World!";


printf("%s\n", str);

float num = 3.14159265;


printf("The value of pi is %.2f\n", num);

2. What is the output of following code?

int x = 5;
int y = 10;

x+= y;

printf("x is %d\n", x);

3. Find error in the below code


#include <stdio.h>

int main() {
printf("Hello, World!")
return 0;
}

#include <stdio.h>

int main() {
int number;
printf("The value of x is %d\n", x);
return 0;
}

#include <stdio.h>

int main() {
printf("This is a syntax error;
return 0;
}

#include <stdio.h>

int main() {
int x = (5 + 3 * (2 - 1);
printf("The value of x is %d\n", x);
return 0;
}

4. What is the primary use of the sizeof operator in C?

5. What is the maximum value that an int data type can hold in C?

6. How do you represent a single-line comment in C?


7. How do you declare a two-dimensional array in C?
8. What is the role of the break statement in a loop?
9. How do you declare a pointer to an int in C?
10. What is the significance of the % operator in C?
11. How do you create an infinite loop in C?
12. What does the getchar function do in C?
13. How do you pass an array to a function in C?
14. Can you return an array from a function in C?
15. How does pass by reference affect memory usage compared to pass by value?
16. What are the advantages of pass by reference?
17. What is the purpose of the "return" statement in a function?
18. Can a function have multiple "return" statements?
19. What happens if you don't include a "return" statement in a function that has a non-
void return type?
20. Can you use the "return" statement in a void function?
21. What is the difference between "return" and "print" statements in C?
22. What are the advantages of using functions in programming?
23. What is a parameter in a function?
24. What is an argument in a function?
25. What is a recursive function?
26. What is the difference between call by value and call by reference in functions?
27. How do you pass an array to a function in C?
28. What is the difference between a character and a string?
29. In C, how are strings terminated?
30. How do you declare a string in C?
31. What is the difference between a string and a character array in C?
32. How do you find the length of a string in C?
33. How do you compare two strings in C?
34. What is the purpose of pointers in programming?
35. How do you declare a pointer in C or C++?
36. How do you find the memory address of a variable in C?
37. What is pointer arithmetic, and when is it used?
38. What is a void pointer (or void*) in C
39. What is a double pointer (or **) and why is it used?
40. What is a double pointer (or **) and why is it used?
41. What happens to the value of a local variable when the function exits?
42. Can local variables be accessed from other functions or outside the block they are defined
in?
43. How do you initialize a local variable in C?
44. What is the scope of a global variable?
45. What is the lifetime of a global variable?
46. How can you access a global variable from within a function in C?
47. What is the difference between global variables and static variables within a function?
48. What are the situations in which you might use global variables in a program?
49. Can global variables have the same name as local variables within a function?
50. How is the scope of a local variable defined?

You might also like