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

C & C Plus Plus
Edit

Describe in Detail

Essay▾
  1. char ⚹foo ()
  2. {
  3.     charresult[100];
  4.     strcpy (result, “anythingisgood” );
  5.     return (result);
  6. }
  7. intmain ()
  8. {
  9.     char ⚹j;
  10.     j =foo ();
  11.     printf ( “%s”, j);
  12. }

Explanation

  • In the program using strcpy () function
  • The C library function char ⚹ strcpy (char ⚹ dest, const char ⚹ src) copies the string pointed to, by “src” to “dest” .
Table Showing the Program
char result [100] ;
  • Define the character result array
strcpy (result, “anything is good” ) ;
  • Using strcpy () function
return (result) ;
  • Return the result
char ⚹ j;
  • Define the character pointer j
j = foo () ;
  • Pointer j calls the foo () function
  • And output is stored in j
printf ( “% s” , j) ;
  • Printf prints the string

Question 187

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the difference between an object and a class?

Explanation

Difference between an Object and a Class
ObjectClass
An instance of a classTemplate from which object are created.
A real world entity an pen, laptop, mobile, bed, keyboard, mouse etc.A group of similar objects.
A physical entity.A logical entity.
Created through “new” keyword.Declared using class keyword e. g. “class Student {} ”
Object is created many times as per requirementDeclared once.
Allocates memory when it is created.doesn՚t allocated memory when it is created

Developed by: