Languages-C & C Plus Plus [TCS Placement]: Sample Questions 49 - 50 of 119

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 49

C & C Plus Plus

Describe in Detail


Is it possible to create your own header files?


  • Yes, it is possible to create a customized header file which include function prototypes used in the program
  • #include directive followed by the name of your header file will be used in the source.
  • How to create own header files in c
  1. Open notepad and write the function used in the program. An example is shown below.
    1. intadd(inta,intb)
    2. {
    3.     return(a+b);
    4. }
  2. Now save the notepad file with . h extension.
  3. In the “c” source file include the header file
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<add.h>//header file created
  4. voidmain()
  5. {
  6.     inta,b,s;
  7.     clrscr();
  8.     printf(“Enterthevalueofaandb:”);
  9.     scanf(“%d%d”,&a,&b);
  10.     s=add(a,b);
  11.     printf(“Add=%d”,s);
  12.     getch();
  13. }

Question 50

C & C Plus Plus



Which of the following is correct about class and structure?


Choice (4)


Pointer to structure or classes cannot be declared.


Class data members are private by default while that of structure are public by default.


Class data members are public by default while that of structure are private.


Class can have member functions while structure cannot.




  • Structure members are public by default and hence can be accessed anywhere in the program through structure variable.
  • Class members, on other hand are private to provide security and code encapsulation.
  • C ++ , structures can also contain member functions, just like in Class- but semantics are same as that of C structures.
  • Here՚s an example:
  1. #include<stdio.h>
  2. structmystruct
  3. {
  4.     inta ;
  5.     voiddisplay(void)
  6.     {
  7.         printf("Hello world...[%d]",a);
  8.     }
  9. } s;
  10. intmain()
  11. {
  12.     s.a=10;
  13.     s.display();
  14.     return0;
  15. }
  • Output:

Hello world … [10]

Developed by: