Practice
Resources
Contests
Online IDE
New
Free Mock
Events New Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
logo
Events
Attend free live masterclass hosted by top tech professionals
New
Scaler
Explore Offerings by SCALER
/ Interview Guides / C Programming MCQ

C Programming MCQ

Last Updated: Dec 11, 2023
Certificate included
About the Speaker
What will you Learn?
Register Now

C is a Procedural Programming Language, mostly written to code an Operating System. C is one of the most famous programming languages and is the forefather of C++, one of the most widely used programming languages today. It has many features some of which are listed below:

  • Easy to understand.
  • Efficient Memory Usage.
  • Usage of Pointers.
  • Fast.
  • Structured Programming Language.
  • Mid-Level Programming Language.
  • Portable on all machines.
  • Rich user library.

Components of a C Program:

The main components constituting a C program are listed below:

  • Header Files: A header file is a file that has an extension .h and contains C function declarations and macros, which are to be shared between several source files, hence allowing reusability and hence more efficiency in building up programming logic.
  • Main Method: The main method is a function from where the program execution starts in C.
  • Program Body: The program body is the main part of the program where all the programming logic is written. It includes all the variable declarations, the program logic(loops, conditional statements, function calls, etc), and finally the return statement terminating the program.
1. 

What will be the result of the following code snippet?

#include <stdio.h>
void solve() {
    char ch[10] = "abcdefghij";
    int ans = 0;
    for(int i = 0; i < 10; i++) {
        ans += (ch[i] - 'a');
    }
    printf("%d", ans);
}
int main() {
    solve();
	return 0;
}
Create a free personalised study plan Create a FREE custom study plan
Get into your dream companies with expert guidance
Get into your dream companies with expert..
Real-Life Problems
Prep for Target Roles
Custom Plan Duration
Flexible Plans
2. 

What will be the output of the following code snippet?

#include <stdio.h>
struct School {
    int age, rollNo;
};
void solve() {
    struct School sc;
    sc.age = 19;
    sc.rollNo = 82;
    printf("%d %d", sc.age, sc.rollNo);
}
int main() {
    solve();
	return 0;
}
3. 

What will be the output of the following code snippet?

#include <stdio.h>
void solve() {
    int a[] = {1, 2, 3, 4, 5};
    int sum = 0;
    for(int i = 0; i < 5; i++) {
        if(i % 2 == 0) {
            sum += *(a + i);
        }
        else {
            sum -= *(a + i);
        }
    }
    printf("%d", sum);
}
int main() {
	solve();
	return 0;
}
4. 

What will be the output of the following code snippet?

#include <stdio.h>
void solve() {
    int x = 2;
    printf("%d", (x << 1) + (x >> 1));
}
int main() {
    solve();
	return 0;
}
5. 

What will be the output of the following code snippet?

#include <stdio.h>
#define VAL 5
int getInput() {
    return VAL;
}
void solve() {
    const int x = getInput();
    printf("%d", x);
}
int main() {
    solve();
	return 0;
}
Explore InterviewBit’s Exclusive Live Events
Explore Exclusive Events
By
No More Events to show!
No More Events to show!
No More Events to show!
No More Events to show!
Certificate included
About the Speaker
What will you Learn?
Register Now
6. 

What will be the output of the following code snippet?

#include <stdio.h>
#define CUBE(x) x * x * x
void solve() {
    int ans = 216 / CUBE(3);
    printf("%d", ans);
}
int main() {
    solve();
	return 0;
}
7. 

What will be the output of the following code snippet?

#include <stdio.h>
void solve() {
    int n = 24;
    int l = 0, r = 100, ans = n;
    while(l <= r) {
        int mid = (l + r) / 2;
        if(mid * mid <= n) {
            ans = mid;
            l = mid + 1;
        }
        else {
            r = mid - 1;
        }
    }
    printf("%d", ans);
}
int main() {
    solve();
	return 0;
}
Start Your Coding Journey With Tracks Start Your Coding Journey With Tracks
Master Data Structures and Algorithms with our Learning Tracks
Master Data Structures and Algorithms
Topic Buckets
Mock Assessments
Reading Material
Earn a Certificate
8. 

What will be the output of the following code snippet?

#include <stdio.h>
void solve() {
    int x = 1, y = 2;
    printf(x > y ? "Greater" : x == y ? "Equal" : "Lesser");
}
int main() {
    solve();
	return 0;
}
9. 

What will be the output of the following code snippet?

#include <stdio.h>
void solve() {
    printf("%d ", 9 / 2);
    printf("%f", 9.0 / 2);
}
int main() {
    solve();
	return 0;
}
10. 

What will be the output of the following code snippet?

#include <stdio.h>
void solve() {
    int first = 10, second = 20;
    int third = first + second;
    {
        int third = second - first;
        printf("%d ", third);
    }
    printf("%d", third);
}
int main() {
	solve();
	return 0;
}
11. 

What will be the output of the following code snippet?

#include <stdio.h>
void solve() {
    bool ok = false;
    printf(ok ? "YES" : "NO");
}
int main() {
    solve();
	return 0;
}
12. 

What will be the output of the following code snippet?

#include <stdio.h>
#define VAL 3 * (2 + 6)
void solve() {
    int a = 10 + VAL;
    printf("%d", a);
}
int main() {
	solve();
	return 0;
}
Discover your path to a   Discover your path to a   Successful Tech Career for FREE! Successful Tech Career!
Answer 4 simple questions & get a career plan tailored for you
Answer 4 simple questions & get a career plan tailored for you
Interview Process
CTC & Designation
Projects on the Job
Referral System
Try It Out
2 Lakh+ Roadmaps Created
13. 

What will be the output of the following code snippet?

#include <stdio.h>
int main() {
	int a = 3, b = 5;
	int t = a;
	a = b;
	b = t;
	printf("%d %d", a, b);
	return 0;
}
14. 

What will be the output of the following code snippet?

#include <stdio.h>
void solve() {
    int ch = 2;
    switch(ch) {
        case 1: printf("1 ");
        case 2: printf("2 ");
        case 3: printf("3 ");
        default: printf("None");
    }
}
int main() {
    solve();
	return 0;
}
15. 

What will be the value of x in the following code snippet?

#include <stdio.h>
void solve() {
    int x = printf("Hello");
    printf(" %d", x);
}
int main() {
	solve();
	return 0;
}
16. 

Which data structure is used to handle recursion in C?

17. 

Which of the following are correct file opening modes in C?

18. 

Which of the following are not standard header files in C?

19. 

Which of the following function is used to open a file in C++?

20. 

Which of the following is an exit controlled loop?

21. 

Which of the following is not a storage class specifier in C?

22. 

Which of the following is not true about structs in C?

23. 

Which of the following is the proper syntax for declaring macros in C?

24. 

Which of the following should be used to free memory from a pointer allocated using the “new” operator?

25. 

Which of the following will occur if we call the free() function on a NULL pointer?

26. 

What is the output of the following code snippet?

int main() {
	int sum = 2 + 4 / 2 + 6 * 2;
	printf("%d", sum);
	return 0;
}
27. 

 What will be the output of the following code snippet?

#include <stdio.h>
union School {
    int age, rollNo;
    double marks;
};
void solve() {
    union School sc;
    sc.age = 19;
    sc.rollNo = 82;
    sc.marks = 19.04;
    printf("%d", (int)sizeof(sc));
}
int main() {
    solve();
	return 0;
}
28. 

How are String represented in memory in C?

29. 

How is an array initialized in C language?

30. 

How is the 3rd element in an array accessed based on pointer notation?

31. 

How to declare a double-pointer in C?

32. 

How to find the length of an array in C?

33. 

If p is an integer pointer with a value 1000, then what will the value of p + 5 be?

34. 

In which of the following languages is function overloading not possible?

35. 

What does the following declaration indicate?

int x: 8;

36. 

What is the disadvantage of arrays in C?

37. 

What is the output of the following code snippet?

#include <stdio.h>
int main() {
	int a[] = {1, 2, 3, 4};
	int sum = 0;
	for(int i = 0; i < 4; i++) {
	    sum += a[i];
	}
	printf("%d", sum);
	return 0;
}
38. 

What is the output of the following code snippet?

#include <stdio.h>
#include<stdlib.h>
void set(int *to) {
    to = (int*)malloc(5 * sizeof(int));
}
void solve() {
    int *ptr;
    set(ptr);
    *ptr = 10;
    printf("%d", *ptr);
}
int main() {
    solve();
	return 0;
}
39. 

 What is the range of values that can be stored by int datatype in C?

40. 

What is the return type of the fopen() function in C?

41. 

What is the size of the int data type (in bytes) in C?

42. 

What will be the output of the following code snippet?

#include <stdio.h>
int get(int n) {
    if(n <= 1) {
        return n;
    }
    return get(n - 1) + get(n - 2);
}
void solve() {
    int ans = get(6);
    printf("%d", ans);
}
int main() {
    solve();
	return 0;
}
43. 

What will be the output of the following code snippet?

#include <stdio.h>
void solve() {
    printf("%d %d", (023), (23));
}
int main() {
    solve();
	return 0;
}
44. 

What will be the output of the following code snippet?

#include <stdio.h>
struct School {
    int age, rollNo;
};
void solve() {
    struct School sc;
    sc.age = 19;
    sc.rollNo = 82;
    printf("%d", (int)sizeof(sc));
}
int main() {
    solve();
	return 0;
}
45. 

What will be the output of the following code snippet?

#include <stdio.h>
void solve() {
    int a = 3;
    int res = a++ + ++a + a++ + ++a;
    printf("%d", res);
}
int main() {
	solve();
	return 0;
}
46. 

What will be the output of the following code snippet?

#include <stdio.h>
void solve() {
    printf("%d %d %d", (076), (28), (0x87));
}
int main() {
    solve();
	return 0;
}
47. 

What will be the output of the following code snippet?

#include <stdio.h>
#include<string.h>
void solve() {
    char s[] = "Hello";
    printf("%s ", s);
    char t[40];
    strcpy(t, s);
    printf("%s", t);
}
int main() {
    solve();
	return 0;
}
48. 

What will be the output of the following code snippet?

#include <stdio.h>
void solve(int x) {
    if(x == 0) {
        printf("%d ", x);
        return;
    }
    printf("%d ", x);
    solve(x - 1);
    printf("%d ", x);
}
int main() {
    solve(3);
	return 0;
}
49. 

What will be the output of the following code snippet?

#include <stdio.h>
void swap(int *a, int *b) {
    int t = *a;
    *a = *b;
    *b = t;
}
void solve() {
    int a = 3, b = 5;
    swap(&a, &b);
    printf("%d %d", a, b);
}
int main() {
	solve();
	return 0;
}
50. 

What will be the output of the following code snippet?

#include <stdio.h>
int search(int l, int r, int target, int a[]) {
    int mid = (l + r) / 2;
    if(a[mid] == target) {
        return mid;
    }
    else if(a[mid] < target) {
        return search(mid + 1, r, target, a);
    }
    else {
        return search(0, mid - 1, target, a);
    }
}
void solve() {
    int a[] = {1, 2, 3, 4, 5};
    printf("%d", search(0, 5, 3, a));
}
int main() {
    solve();
	return 0;
}
Excel at your interview with Masterclasses Know More
Certificate included
What will you Learn?
Free Mock Assessment
Fill up the details for personalised experience.
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
Graduation Year *
Graduation Year *
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
*Enter the expected year of graduation if you're student
Current Employer
Company Name
College you graduated from
College/University Name
Job Title
Job Title
Engineering Leadership
Software Development Engineer (Backend)
Software Development Engineer (Frontend)
Software Development Engineer (Full Stack)
Data Scientist
Android Engineer
iOS Engineer
Devops Engineer
Support Engineer
Research Engineer
Engineering Intern
QA Engineer
Co-founder
SDET
Product Manager
Product Designer
Backend Architect
Program Manager
Release Engineer
Security Leadership
Database Administrator
Data Analyst
Data Engineer
Non Coder
Other
Please verify your phone number
Edit
Resend OTP
By clicking on Start Test, I agree to be contacted by Scaler in the future.
Already have an account? Log in
Free Mock Assessment
Instructions from Interviewbit
Start Test