Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 105 - 107 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 105

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Write program for string reversal & palindrome check.

Explanation

  1. #include<stdio.h>
  2. #include<string.h>
  3. main()
  4. {
  5.     charstr[50], revst [50];
  6.     inti=0, j=0;
  7.     printf(“enterthestringtoreversed:“);
  8.     scanf(“%s”, str);
  9.     for(i=strlen(str)-1;i>0;i--)
  10.     {
  11.         revst[j]=str[i];
  12.         j++;
  13.     };
  14.     revstr[j]=”;
  15.     printf(“inputstring :%s”, str);
  16.     printf(“outputstring:%s”, revstr);
  17.     getch();
  18. }

Question 106

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Define namespace?

Explanation

  • It is a feature in c ++ to minimize name collisions in the global name space.
  • This namespace keyword assigns a distinct name to a library that allows other libraries to use the same identifier names without creating any name collisions.
  • Compiler uses the namespace signature for differentiating the definitions.
Define the How to Use the Namespaces in C ++

Question 107

C & C Plus Plus
Edit

Describe in Detail

Essay▾
  1. main ()
  2. {
  3.     staticcharnames[5][20] ={ “pascal” “ada” “cobol” “fortran” “perl” };
  4.     inti;
  5.     char ⚹t;
  6.     t =names[3];
  7.     names[3] =names[4];
  8.     names[4] =t;
  9.     for (i =0; i ⇐ 4; i ++ )
  10.     printf ( “%s” names[i]);
  11. }

Explanation

  • In a program ,
Table Shows the Program
static char names [5] [20] = { “pascal” “ada” “cobol” “fortran” “perl” } ;Given the static character 2D array.
int i;Assign integer variable i.
char ⚹ t;Given the character pointer t.
t = names [3] ;Given the t = name [3] ;

So, t = fortran

names [3] = names [4] ;Here name [3] = fortran

so, fortran = names [4] ;

names [4] = t;Here names [4] = fortran

So, fortran = t;

for (i = 0; i ⇐ 4; i ++)

printf ( “% s” names [i] ) ;

Apply for loop

And print names [i]

But, Array names are pointer constant

So, they can՚t be modified

  • So the answer is Compiler error: L value required in function main

Developed by: