C Programs
TYPEDEF

1. What can be said of the following program ?
main()
{
enum Months {JAN =1,FEB,MAR,APR};
Months X = JAN;
if(X==1)
{
printf("Jan is the first month");
}
}
a) Does not print anything
b) Prints : Jan is the first month
c) Generates compilation error
d) Results in runtime error
Answer : b

2.main()
    {
           extern int i;
           i=20;
           printf("%d",i);
     }

           Answer:
                   Linker Error : Undefined symbol '_i'
          Explanation:
extern storage class in the following declaration,
                              extern int i;
specifies to the compiler that the memory for iis allocated in some other program and that address
will be given to the current program at the time of linking. But linker finds that no other variable of
name iis available in any other program with memory space allocated for it. Hence a linker error has
occurred .

3. enum colors {BLACK,BLUE,GREEN}
         main()
         {

           printf("%d..%d..%d",BLACK,BLUE,GREEN);

           return(1);
           }
           Answer:
                     0..1..2
           Explanation:
                     enum assigns numbers starting from 0, if not explicitly defined.




PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450   / 96000 66689
                 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli
                Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses.
                                            www.pantechprojects.com
4. Given the following statement enum day = { jan = 1 ,feb=4, april, may} What is the value
of may?
(a) 4
(b) 5
(c) 6
(d) 11
(e) None of the above
Answer c) 6

SWITCH:

5. What is the output of the following program?
main()
{
int l=6;
switch(l)
{ default : l+=2;
case 4: l=4;
case 5: l++;
break;
}
printf("%d",l);
}
a)8 b)6 c)5 d)4 e)none

Answer : c) 5

    6. main()
    {
         int i=3;
         switch(i)
         {
         default:printf("zero");
         case 1: printf("one");
                   break;
         case 2:printf("two");
                   break;
         case 3: printf("three");
                   break;
         }
    }
         Answer :
                   three
         Explanation :
                   The default case can be placed anywhere inside the loop. It is executed only when all
other cases doesn't match.

7.        #include<stdio.h>
          main()
          {
          int i=1,j=2;
          switch(i)
          {




PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450   / 96000 66689
                 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli
                Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses.
                                            www.pantechprojects.com
case 1: printf("GOOD");
                     break;
            case j: printf("BAD");
            break;
            }
            }
            Answer:
                     Compi ler Error: Constant expression required in function main.
            Explanation:
                     The case statement can have only constant expressions (this implies that we cannot
                     use variable names directly so an error).
            Note:
                     Enumerated types can be used in case statements.

8. main()
            {
                      float i=1.5;
                      switch(i)
                      {
                                case 1: printf("1");
                                case 2: printf("2");
                                default : printf("0");
                      }
            }
            Answer:
                    Compi ler Error: switch expression not integral
            Explanation:
                    Switch statements can be applied only to integral types.

10. Output of the following program is
main()
{
        int i=0;
        for(i=0;i<20;i++)
        {
        switch(i)
        case 0:i+=5;
        case 1:i+=2;
        case 5:i+=5;
        default i+=4;
        break;
        }
        printf("%d,",i);
        }
}

a) 0,5,9,13,17
b) 5,9,13,17
c) 12,17,22
d) 16,21
e) Syntax error

Ans. (d)




PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450   / 96000 66689
                 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli
                Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses.
                                            www.pantechprojects.com
11. main()
{
int i;
for(i=0;i<3;i++)
switch(i)
{
case 1: printf("%d",i);
case 2 : printf("%d",i);
default: printf("%d"i);
}
}
 Answer: 011122

FUNCTIONS:

12. What is the output of the following program?
main()
{
int x=20;
int y=10;
swap(x,y);
printf("%d %d",y,x+2);
}
swap(int x,int y)
{
int temp;
temp =x;
x=y;
y=temp;
}

    a) 10,20 b) 20,12 c) 22,10 d)10,22 e)none


Answer : d)10,22

13. Which of the following about the following two declaration is true
i ) int *F()
ii) int (*F)()
 Choice :
a) Both are identical
b) The first is a correct declaration and the second is wrong
c) The first declaraion is a function returning a pointer to an integer and the second is a
pointer to              function returning int
d) Both are different ways of declarin pointer to a function

          Answer : c).

     14. main()
     {
         printf("%p",main);
     }




PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450   / 96000 66689
                 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli
                Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses.
                                            www.pantechprojects.com
Answer:
                   Some address will be printed.
         Explanation:
         Function names are just addresses (just like array names are addresses).
main() is also a function. So the address of function main will be printed. %p in printf specifies that
the argument is an address. They are printed as hexadecimal numbers.

15. main()
         {
         clrscr();
         }
         clrscr();

          Answer:
                  No output/error
          Explanation:
                  The first clrscr() occurs inside a function. So it becomes a function call. In the second
                  clrscr(); is a function declaration (because it is not inside any function).

16.      main()
         {
         int i;
         printf("%d",scanf("%d",&i)); // value 10 is given as input here
         }
         Answer:
                  1
         Explanation:
Scanf returns number of items successfully read and not 1/0. Here 10 is given as input which should
have been scanned successfully. So number of items read is 1.

17. main()
         {
         show();
         }
         void show()
         {
         printf("I'm the greatest");
         }
         Answer:
                   Compi er error: Type mismatch in redeclaration of show.
         Explanation:
                   When the compiler sees the function show it doesn't know anything about it. So the
                   default return type (ie, int) is assumed. But when compiler sees the actual definition
                   of show mismatch occurs since it is declared as void. Hence the error.
                   The solutions are as follows:
                            1. declare void show() in main() .
                            2. define show() before main().
                            3. declare extern void show() before the use of show().

18. main()
         {
         main();
         }




PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450   / 96000 66689
                 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli
                Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses.
                                            www.pantechprojects.com
Answer:
                  Runtime error : Stack overflow.
          Explanation:
                   main function calls itself again and again. Each time the function is called its return
                   address is stored in the call stack. Since there is no condition to terminate the
                   function call, the call stack overflows at runtime. So it terminates the program and
                   results in an error.

19. What are the following notations of defining functions known as?
         i.       int abc(int a,float b)
{
/* some code */
                    }
         ii.    int abc(a,b)
         int a; float b;
{
/* some code*/
}
         Answer:
                    i. ANSI C notati on
                    ii. Kernighan & Ritche notation



     20. What is printed when this program is executed
     main()
     {
     printf ("%dn",f(7));
     }
     f(X)
     {

                                       if ( x<= 4)
     return x;

     return f(--x);
     }
     a) 4
     b)5
     c) 6
     d) 7

     Answer : a)


     21. what is printed when the following program is compiled and executed?
     int    func (int x)
     {
     if (x<=0)
     return(1);
     return func(x -1) +x;

     }
     main()




PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450   / 96000 66689
                 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli
                Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses.
                                            www.pantechprojects.com
{
     printf("%dn",func(5));
     }
     a) 12
     b) 16
     c) 15
     d) 11

          Answer : .b) 16.

     22. Find the out put:
                   main()
                   {
                   int a==4
sqrt(a);
printf("%d",a);
                   }
1).2.0         2). 2       3). 4.0              4). 4
                  Answer : 2

23. Find the output
main()
{
int a[]={ 2,4,6,8,10 };
int i;
                     change(a,5);
                     for( i = 0; i <= 4; i++)
                     printf("n %d",a[i]);
          }
          change( int *b, int n)
          {
          int i;
          for( i = 0; i < n; i++)
          *(b+i) = *(b+i) + 5;
          }
Answer:



24. #include<studio.h>
main()
{
func(1);
}
func(int i){
static char *str[] ={ "One","Two","Three","Four"};
printf("%sn",str[i++]);
return;
}
Answer:- it will give warning because str is pointer to the char but
it is initialized with more values
if it is not considered then the answer is Two */




PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450   / 96000 66689
                 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli
                Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses.
                                            www.pantechprojects.com
25. Find the out put:

#include<stdio.h>
/* This problem was asked in PCS Bombay in a walk-in-interview
Write a recursive function that calculates
n * (n-1) * (n-2) * ....... 2 * 1 */

main() {
int factorial(int n);
int i,ans;
printf("n Enter a Number:");
scanf("%d",&i);
ans = factorial(i);
printf("nFactorial by recursion = %dn", ans);
}
int factorial(int n)
{
if (n <= 1) return (1);
else
return ( n * factorial(n-1));
}

Answer :

26.Find the output

#include <stdio.h>
main()
{
int j,ans;
j = 4;
ans = count(4);
printf("%dn",ans);
}

int count(int i)
{
if ( i < 0) return(i);
else
return( count(i-2) + count(i-1));
}
Answer :

/* It is showing -18 as an answer */

     27. Find the out put

      int x;
      main()
      {
      int x=0;
      {




PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450   / 96000 66689
                 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli
                Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses.
                                            www.pantechprojects.com
int x=10;
      x++;
      change_value(x);
      x++;
      Modify_value();
      printf("First output : %dn",x);
      }
      x++;

      change_value(x);
      printf("Second Output : %dn",x);
      Modify_value();
      printf("Third Output : %dn",x);
      }

     Modify_val ue()
     {
     return (x+=10);
     }
     change_value()
     {
     return(x+=1);
     }
     Answer :




28. Consider the following program
main()
{
int i=20,*j=&i;
f1(j);
*j+=10;
f2(j);
printf("%d and %d",i,*j);
}
f1(k)
int *k;
{
*k +=15;
}

f2(x)
int *x;
{
int m=*x,*n=&m;
*n += 10;
}

The values printed by the program will be
a) 20 and 55
b) 20 and 45
c) 45 and 45




PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450   / 96000 66689
                 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli
                Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses.
                                            www.pantechprojects.com
d) 45 and 55
e) 35 and 35
Answer : c

29. what is printed when the following program is
compiled and executed?

int func (int x)
{
if (x<=0)
return(1);
return func(x -1) +x;
}
main()
{
printf("%dn",func(5));
}

a) 12
b) 16
c) 15
d) 11
Answer : b


STRUCTURE AND UNION:

30. What is the size of the following union. Assume that the size of int =2, size of float =4 and size of
char =1.

Union Tag
{
int a;
float b;
char c;
};

a)2       b)4c)1 d) 7

Answer : b



DATA TYPES
     31. What is th output of the fol lowing program?
int x= 0x65;
main()
{
char x;
printf("%dn",x)
}
a) compilation error    b) 'A'     c) 65       d) unidentified




PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450   / 96000 66689
                 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli
                Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses.
                                            www.pantechprojects.com
Answer : c




PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450   / 96000 66689
                 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli
                Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses.
                                            www.pantechprojects.com

More Related Content

PDF
Deep C
PDF
Develop Embedded Software Module-Session 2
PDF
Develop Embedded Software Module-Session 3
PDF
VTU PCD Model Question Paper - Programming in C
PDF
answer-model-qp-15-pcd13pcd
PDF
Solid C++ by Example
PDF
C Prog. - Decision & Loop Controls
PPT
Lecture#5 c lang new
Deep C
Develop Embedded Software Module-Session 2
Develop Embedded Software Module-Session 3
VTU PCD Model Question Paper - Programming in C
answer-model-qp-15-pcd13pcd
Solid C++ by Example
C Prog. - Decision & Loop Controls
Lecture#5 c lang new

What's hot (20)

PDF
Data structure week 1
DOCX
Simulado java se 7 programmer
PDF
88 c-programs
PPTX
C programming slide-6
PPTX
C programming-apurbo datta
PPT
Lecture 2
PDF
C programming session3
DOCX
C++ lab assignment
PDF
Programming with c language practical manual
PDF
PHP Reviewer
PPTX
C Programming Unit-1
PPT
Kuliah komputer pemrograman
PPT
Paradigmas de Linguagens de Programacao - Aula #5
PDF
Fnt software solutions placement paper
PDF
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
PDF
02. functions & introduction to class
PPTX
Claguage 110226222227-phpapp02
 
PDF
Oop Presentation
PDF
Mid term sem 2 1415 sol
 
Data structure week 1
Simulado java se 7 programmer
88 c-programs
C programming slide-6
C programming-apurbo datta
Lecture 2
C programming session3
C++ lab assignment
Programming with c language practical manual
PHP Reviewer
C Programming Unit-1
Kuliah komputer pemrograman
Paradigmas de Linguagens de Programacao - Aula #5
Fnt software solutions placement paper
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
02. functions & introduction to class
Claguage 110226222227-phpapp02
 
Oop Presentation
Mid term sem 2 1415 sol
 
Ad

Viewers also liked (7)

PPT
Gender research final project
PPT
Gender Education
PDF
SOC 463/663 (Social Psych of Education) - Gender & Education
PDF
Learn BEM: CSS Naming Convention
PDF
SEO: Getting Personal
PDF
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
PDF
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Gender research final project
Gender Education
SOC 463/663 (Social Psych of Education) - Gender & Education
Learn BEM: CSS Naming Convention
SEO: Getting Personal
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Ad

Similar to Aptitute question papers in c (20)

PPTX
Function in C program
PPT
L4 functions
PDF
Fundamentals of programming)
PPT
Lec 10
PPT
An imperative study of c
PPTX
Functions in C
PPTX
Introduction to Basic C programming 02
PPT
85ec7 session2 c++
PPTX
Switch statement mcq
DOCX
C interview question answer 2
PPTX
1 introduction to c program
PPTX
Fundamentals of prog. by rubferd medina
PPTX
fundamentals of softweare engeneering and programming in C.pptx
PPT
Session 3
PPTX
Final project powerpoint template (fndprg) (1)
 
PPT
C tutorial
PPTX
3. chapter ii
DOCX
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
PDF
C question-answer-bank
PPT
asdasdqwdsadasdsadsadasdqwrrweffscxv wsfrt
Function in C program
L4 functions
Fundamentals of programming)
Lec 10
An imperative study of c
Functions in C
Introduction to Basic C programming 02
85ec7 session2 c++
Switch statement mcq
C interview question answer 2
1 introduction to c program
Fundamentals of prog. by rubferd medina
fundamentals of softweare engeneering and programming in C.pptx
Session 3
Final project powerpoint template (fndprg) (1)
 
C tutorial
3. chapter ii
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C question-answer-bank
asdasdqwdsadasdsadsadasdqwrrweffscxv wsfrt

More from Pantech ProEd Pvt Ltd (20)

PDF
2013 14-ns2-project-titles-me-mtech
PDF
2013 14-embedded-project-titles-pantech-me-m tech-project-titles
PDF
2013 14-dotnet-titles-pantech-proed-for-me-mtech
PDF
2013 14-java-project-titles-me-tech-pantech
PDF
2013 14-power-electronics-project-titles-me-mtech
PDF
2013 14-power-systems-project-titles-for-me-m-tech-pantech
PDF
2013 14-vlsi-project-titles-for-me-mtech-pantech-pro ed
PDF
plc_2012-13_titles
PDF
8. _power_system_2012-13
PDF
6. _dotnet_2012-13.doc
PDF
5. _java_2012-13_titles
PDF
4. _vlsi_2012-13_titles
PDF
3. _dsp_2012-13_titles
PDF
2. _embedded_project_titles_2012-13-final
PDF
1. _ns2_2012-13_titles.doc
PDF
7. _power_electronics_2012-13_titles
PDF
Mahindra satyam-2010-banglore.docx
PDF
Hexaware mock test1
PDF
Cts aptitude questio papers
PDF
Syntel model placement paper 2
2013 14-ns2-project-titles-me-mtech
2013 14-embedded-project-titles-pantech-me-m tech-project-titles
2013 14-dotnet-titles-pantech-proed-for-me-mtech
2013 14-java-project-titles-me-tech-pantech
2013 14-power-electronics-project-titles-me-mtech
2013 14-power-systems-project-titles-for-me-m-tech-pantech
2013 14-vlsi-project-titles-for-me-mtech-pantech-pro ed
plc_2012-13_titles
8. _power_system_2012-13
6. _dotnet_2012-13.doc
5. _java_2012-13_titles
4. _vlsi_2012-13_titles
3. _dsp_2012-13_titles
2. _embedded_project_titles_2012-13-final
1. _ns2_2012-13_titles.doc
7. _power_electronics_2012-13_titles
Mahindra satyam-2010-banglore.docx
Hexaware mock test1
Cts aptitude questio papers
Syntel model placement paper 2

Recently uploaded (20)

PPTX
Microsoft Excel 365/2024 Beginner's training
PDF
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PDF
CloudStack 4.21: First Look Webinar slides
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PPT
Geologic Time for studying geology for geologist
PDF
Comparative analysis of machine learning models for fake news detection in so...
PPTX
The various Industrial Revolutions .pptx
PDF
Produktkatalog fĂĽr HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PPT
Module 1.ppt Iot fundamentals and Architecture
PPTX
Benefits of Physical activity for teenagers.pptx
PPTX
Chapter 5: Probability Theory and Statistics
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PDF
Developing a website for English-speaking practice to English as a foreign la...
Microsoft Excel 365/2024 Beginner's training
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
OpenACC and Open Hackathons Monthly Highlights July 2025
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
CloudStack 4.21: First Look Webinar slides
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Enhancing plagiarism detection using data pre-processing and machine learning...
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
A review of recent deep learning applications in wood surface defect identifi...
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Geologic Time for studying geology for geologist
Comparative analysis of machine learning models for fake news detection in so...
The various Industrial Revolutions .pptx
Produktkatalog fĂĽr HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
Module 1.ppt Iot fundamentals and Architecture
Benefits of Physical activity for teenagers.pptx
Chapter 5: Probability Theory and Statistics
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
Developing a website for English-speaking practice to English as a foreign la...

Aptitute question papers in c

  • 1. C Programs TYPEDEF 1. What can be said of the following program ? main() { enum Months {JAN =1,FEB,MAR,APR}; Months X = JAN; if(X==1) { printf("Jan is the first month"); } } a) Does not print anything b) Prints : Jan is the first month c) Generates compilation error d) Results in runtime error Answer : b 2.main() { extern int i; i=20; printf("%d",i); } Answer: Linker Error : Undefined symbol '_i' Explanation: extern storage class in the following declaration, extern int i; specifies to the compiler that the memory for iis allocated in some other program and that address will be given to the current program at the time of linking. But linker finds that no other variable of name iis available in any other program with memory space allocated for it. Hence a linker error has occurred . 3. enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); } Answer: 0..1..2 Explanation: enum assigns numbers starting from 0, if not explicitly defined. PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450 / 96000 66689 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses. www.pantechprojects.com
  • 2. 4. Given the following statement enum day = { jan = 1 ,feb=4, april, may} What is the value of may? (a) 4 (b) 5 (c) 6 (d) 11 (e) None of the above Answer c) 6 SWITCH: 5. What is the output of the following program? main() { int l=6; switch(l) { default : l+=2; case 4: l=4; case 5: l++; break; } printf("%d",l); } a)8 b)6 c)5 d)4 e)none Answer : c) 5 6. main() { int i=3; switch(i) { default:printf("zero"); case 1: printf("one"); break; case 2:printf("two"); break; case 3: printf("three"); break; } } Answer : three Explanation : The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match. 7. #include<stdio.h> main() { int i=1,j=2; switch(i) { PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450 / 96000 66689 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses. www.pantechprojects.com
  • 3. case 1: printf("GOOD"); break; case j: printf("BAD"); break; } } Answer: Compi ler Error: Constant expression required in function main. Explanation: The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error). Note: Enumerated types can be used in case statements. 8. main() { float i=1.5; switch(i) { case 1: printf("1"); case 2: printf("2"); default : printf("0"); } } Answer: Compi ler Error: switch expression not integral Explanation: Switch statements can be applied only to integral types. 10. Output of the following program is main() { int i=0; for(i=0;i<20;i++) { switch(i) case 0:i+=5; case 1:i+=2; case 5:i+=5; default i+=4; break; } printf("%d,",i); } } a) 0,5,9,13,17 b) 5,9,13,17 c) 12,17,22 d) 16,21 e) Syntax error Ans. (d) PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450 / 96000 66689 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses. www.pantechprojects.com
  • 4. 11. main() { int i; for(i=0;i<3;i++) switch(i) { case 1: printf("%d",i); case 2 : printf("%d",i); default: printf("%d"i); } } Answer: 011122 FUNCTIONS: 12. What is the output of the following program? main() { int x=20; int y=10; swap(x,y); printf("%d %d",y,x+2); } swap(int x,int y) { int temp; temp =x; x=y; y=temp; } a) 10,20 b) 20,12 c) 22,10 d)10,22 e)none Answer : d)10,22 13. Which of the following about the following two declaration is true i ) int *F() ii) int (*F)() Choice : a) Both are identical b) The first is a correct declaration and the second is wrong c) The first declaraion is a function returning a pointer to an integer and the second is a pointer to function returning int d) Both are different ways of declarin pointer to a function Answer : c). 14. main() { printf("%p",main); } PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450 / 96000 66689 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses. www.pantechprojects.com
  • 5. Answer: Some address will be printed. Explanation: Function names are just addresses (just like array names are addresses). main() is also a function. So the address of function main will be printed. %p in printf specifies that the argument is an address. They are printed as hexadecimal numbers. 15. main() { clrscr(); } clrscr(); Answer: No output/error Explanation: The first clrscr() occurs inside a function. So it becomes a function call. In the second clrscr(); is a function declaration (because it is not inside any function). 16. main() { int i; printf("%d",scanf("%d",&i)); // value 10 is given as input here } Answer: 1 Explanation: Scanf returns number of items successfully read and not 1/0. Here 10 is given as input which should have been scanned successfully. So number of items read is 1. 17. main() { show(); } void show() { printf("I'm the greatest"); } Answer: Compi er error: Type mismatch in redeclaration of show. Explanation: When the compiler sees the function show it doesn't know anything about it. So the default return type (ie, int) is assumed. But when compiler sees the actual definition of show mismatch occurs since it is declared as void. Hence the error. The solutions are as follows: 1. declare void show() in main() . 2. define show() before main(). 3. declare extern void show() before the use of show(). 18. main() { main(); } PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450 / 96000 66689 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses. www.pantechprojects.com
  • 6. Answer: Runtime error : Stack overflow. Explanation: main function calls itself again and again. Each time the function is called its return address is stored in the call stack. Since there is no condition to terminate the function call, the call stack overflows at runtime. So it terminates the program and results in an error. 19. What are the following notations of defining functions known as? i. int abc(int a,float b) { /* some code */ } ii. int abc(a,b) int a; float b; { /* some code*/ } Answer: i. ANSI C notati on ii. Kernighan & Ritche notation 20. What is printed when this program is executed main() { printf ("%dn",f(7)); } f(X) { if ( x<= 4) return x; return f(--x); } a) 4 b)5 c) 6 d) 7 Answer : a) 21. what is printed when the following program is compiled and executed? int func (int x) { if (x<=0) return(1); return func(x -1) +x; } main() PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450 / 96000 66689 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses. www.pantechprojects.com
  • 7. { printf("%dn",func(5)); } a) 12 b) 16 c) 15 d) 11 Answer : .b) 16. 22. Find the out put: main() { int a==4 sqrt(a); printf("%d",a); } 1).2.0 2). 2 3). 4.0 4). 4 Answer : 2 23. Find the output main() { int a[]={ 2,4,6,8,10 }; int i; change(a,5); for( i = 0; i <= 4; i++) printf("n %d",a[i]); } change( int *b, int n) { int i; for( i = 0; i < n; i++) *(b+i) = *(b+i) + 5; } Answer: 24. #include<studio.h> main() { func(1); } func(int i){ static char *str[] ={ "One","Two","Three","Four"}; printf("%sn",str[i++]); return; } Answer:- it will give warning because str is pointer to the char but it is initialized with more values if it is not considered then the answer is Two */ PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450 / 96000 66689 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses. www.pantechprojects.com
  • 8. 25. Find the out put: #include<stdio.h> /* This problem was asked in PCS Bombay in a walk-in-interview Write a recursive function that calculates n * (n-1) * (n-2) * ....... 2 * 1 */ main() { int factorial(int n); int i,ans; printf("n Enter a Number:"); scanf("%d",&i); ans = factorial(i); printf("nFactorial by recursion = %dn", ans); } int factorial(int n) { if (n <= 1) return (1); else return ( n * factorial(n-1)); } Answer : 26.Find the output #include <stdio.h> main() { int j,ans; j = 4; ans = count(4); printf("%dn",ans); } int count(int i) { if ( i < 0) return(i); else return( count(i-2) + count(i-1)); } Answer : /* It is showing -18 as an answer */ 27. Find the out put int x; main() { int x=0; { PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450 / 96000 66689 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses. www.pantechprojects.com
  • 9. int x=10; x++; change_value(x); x++; Modify_value(); printf("First output : %dn",x); } x++; change_value(x); printf("Second Output : %dn",x); Modify_value(); printf("Third Output : %dn",x); } Modify_val ue() { return (x+=10); } change_value() { return(x+=1); } Answer : 28. Consider the following program main() { int i=20,*j=&i; f1(j); *j+=10; f2(j); printf("%d and %d",i,*j); } f1(k) int *k; { *k +=15; } f2(x) int *x; { int m=*x,*n=&m; *n += 10; } The values printed by the program will be a) 20 and 55 b) 20 and 45 c) 45 and 45 PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450 / 96000 66689 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses. www.pantechprojects.com
  • 10. d) 45 and 55 e) 35 and 35 Answer : c 29. what is printed when the following program is compiled and executed? int func (int x) { if (x<=0) return(1); return func(x -1) +x; } main() { printf("%dn",func(5)); } a) 12 b) 16 c) 15 d) 11 Answer : b STRUCTURE AND UNION: 30. What is the size of the following union. Assume that the size of int =2, size of float =4 and size of char =1. Union Tag { int a; float b; char c; }; a)2 b)4c)1 d) 7 Answer : b DATA TYPES 31. What is th output of the fol lowing program? int x= 0x65; main() { char x; printf("%dn",x) } a) compilation error b) 'A' c) 65 d) unidentified PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450 / 96000 66689 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses. www.pantechprojects.com
  • 11. Answer : c PANTECH SOLUTIONS PVT LTD , 151 / 34 , Sri Renga Building , T Nagar , Chennai – 17 Tel : 044 42606450 / 96000 66689 Branches @ Madurai , Coimbatore, Cochin , Pune, Hyderabad and Tirunelveli Pantech Potency : Final Year IEEE / Non IEEE Projects and Professional Courses. www.pantechprojects.com