C Programming Quiz – Set 2

Programming Questions & Answers -
Who should Practice these C Questions?
- Anyone wishing to sharpen their skills on C programming language
- Anyone preparing for aptitude test in C (both objective type test and C coding written test)
- Anyone preparing for interviews (campus/off-campus interviews, walk-in interview and company interviews)

#1: What is the scope of an external variable?
a) Whole source file in which it is defined
b) From the point of declaration to the end of the file in which it is defined
c) Any source file in a program
d) From the point of declaration to the end of the file being compiled

Show Answer

#2: What is the output of this C code?

#include <stdio.h>
void main()
{
	int x = 97;
	int y = sizeof(x++);
	printf("x is %d", x);
}

a) x is 97
b) x is 98
c) x is 99
d) Run time error

Show Answer

#3: What is the output of the below c code?

#include <stdio.h>
void main()
{
	char *s = "hello";
	char *p = s;
	printf("%p\t%p", p, s);
}

a) Different address is printed
b) Same address is printed
c) Run time error
d) Nothing

Show Answer

#4: What is the output of this C code?

#include <stdio.h>
struct student
{
	char a[5];
};
void main()
{
	struct student s[] = {"hi", "hey"};
	printf("%c", s[0].a[1]);
}

a) h
b) i
c) e
d) y

Show Answer

#5: What is the output of this C code?

#include <stdio.h>
void main()
{
	static int x;
	if (x++ < 2)
	main();
}

a) Infinite calls to main
b) Run time error
c) Varies
d) main is called twice

Show Answer

#6: What is the output of this C code?

#include <stdio.h>
int main()
{
	char *str = "hello, world";
	char *str1 = "hello, world";
	if (strcmp(str, str1))
		printf("equal");
	else
		printf("unequal");
}

a) equal
b) unequal
c) Compilation error
d) Depends on the compiler

Show Answer

#7: Which of the following cannot be static in C?
a) Variables
b) Functions
c) Structures
d) None of the mentioned

Show Answer

#8: What is the output of this C code?

#include <stdio.h>
#define foo(m, n) m * n = 10
int main()
{
	printf("in main\n");
}

a) In main
b) Compilation error as lvalue is required for the expression m*n=10
c) Preprocessor error as lvalue is required for the expression m*n=10
d) None of the mentioned

Show Answer

#9: Which of the following is not possible?
a) A structure variable pointing to itself
b) A structure variable pointing to another structure variable of same type
c) 2 different type of structure variable pointing at each other.
d) None of these

Show Answer

#10: Property of external variable to be accessed by any source file is called by C90 standard as
a) external linkage
b) external scope
c) global scope
d) global linkage

Show Answer

10 Thoughts on “C Programming Quiz – Set 2

  1. Naina Garg on April 9, 2015 at 5:59 pm said:

    please explain question #6?

    • Anand on June 23, 2016 at 11:44 am said:

      dude, strcmp returns zero when the strings are equal. so if statement doesn’t execute in the example

    • Its actually comparing the address..If that must return true then it must be like
      strcmp(*str,*str1);Then this would compare the values stored in the respective variables.

  2. abhishek on April 25, 2015 at 10:37 pm said:

    it comparing a pointer address

  3. satakshi on May 16, 2015 at 1:23 am said:

    in c , any function returns 0 as answer,if it is true
    in #6,strcmp() ,on comparing both strings it gets TRUE as answer which is actually 0
    on evaluating if(),condition being 0 as answer it gets false and else part executes
    that’s why
    answer-unequal

  4. karthikanna on August 25, 2015 at 7:40 pm said:

    pls…explain me questions…4,6

    • Ranjeet Kumar on September 14, 2015 at 5:48 pm said:

      4) struct student s[] has two element {“hi”, “hey”};
      at s[0] = “hi” and at s[1] =”hey”
      struct student has a character variable ‘a’ with size 5;

      So ,if printf(“%c”, s[0].a[1]); output will be “hi”.a[1] means i the 1st location “hi”

      same if printf(“%c”, s[1].a[1]); output will be e

  5. Siva sankaran on December 21, 2017 at 4:07 pm said:

    Please explain question no 4

  6. Pankaj mandal on August 18, 2019 at 10:34 am said:

    New program want to know

  7. Mark Chen on October 3, 2019 at 9:00 am said:

    Question 2: the answer should be b) x is 98
    since int y = sizeof(x++); => int y = sizeof(x); x=x+1;

Leave a Reply to Ranjeet Kumar Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Post Navigation