Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 262 - 263 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 262

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. #definemax5
  2. #defineintarr1[max]
  3. main ()
  4. {
  5.     typedefchararr2[max];
  6.     arr1list ={ 0, 1, 2, 3, 4};
  7.     arr2name =“name”;
  8.     printf ( “%d %s” list[0], name);
  9. }

Explanation

  • Compiler error (in the line arr1 list = {0,1, 2,3, 4} )
  • In a program
Table Shows the Program
#define max 5Define the pre declaration max = 5
#define int arr1 [max]Also define integer arr1 [max]
typedef char arr2 [max] ;
  • arr2 is declared of type array of size 5 characters.
  • So it can be used to declare the variable name of the type arr2.
  • But same is not the case with arr1 (arr1 list = {0, 1,2, 3,4} ;)
  • Hence an error
  • #defines are used for textual replacement whereas typedefs are used for declaring new types.

Question 263

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. main ()
  2. {
  3.     char ⚹cptr, c;
  4.     void ⚹vptr, v;
  5.     c =10;
  6.     v =0;
  7.     cptr=&c;
  8.     vptr=&v;
  9.     printf(“%c%vc,v);
  10. }

Explanation

  • Compiler error (at line number 4) : size of v is Unknown.
  • In a program
    Table Shows the Program
    char ⚹ cptr, c;Create character pointer and variable
    void ⚹ vptr, v;creating variable vptr of type void ⚹ and v of type void
    c = 10;Define the value c = 10;
    v = 0;Here v was void is defined to v = 0

    So, compiler error: size of v is unknown.

  • You can create a variable of type void ⚹ but not of type void, since void is an empty type with unknown size. Pointer void can point to any variable type

Developed by: