Languages [3i Infotech Placement]: Sample Questions 297 - 298 of 546

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

Question 297

Languages
Edit

Describe in Detail

Essay▾

External variables can be accessed.

Explanation

  • External variables can accesses functions.
  • A variable defined outside any function block.
  • A local variable is a variable defines inside a function block.
  • Alternative to automatic variables, it is possible to define variables that are external to all functions, that is, variables that can be accessed by name by any function.
  • Globally accessible, they can be used instead of argument lists to communicate data between functions.
  • Remain in existence permanently, rather than appearing and disappearing as functions are called and exited.
  • They retain their values even after the functions that set them have returned.

Question 298

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

Developed by: