Languages [Accenture Placement]: Sample Questions 5 - 7 of 9

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 5

Edit

Write in Short

Short Answer▾
  1. Voidmain ()
  2. {
  3.     intconst ⚹=5;
  4.     printf(“%d”++(⚹p));
  5. }

Explanation

  • In a program
    Table Shows the Program
    int const ⚹ p = 5;Pointer to constant integer
    printf ( “% d” ++ (⚹ p) ) ;We tried to change constant integer value
  • But constant value can՚t change
  • So, the answer is Compiler error: Cannot modify a constant value.

Question 6

Edit

Describe in Detail

Essay▾
  1. Main ()
  2. {
  3.     Staticintvar =5;
  4.     Printf (“%d” var--);
  5.     if (var)
  6.     main ();
  7. }

Explanation

Table Shows the Program
Static int var = 5Give static integer value
Printf ( “% d” var-)Decrease the integer value
if (var)If condition checks whether integer variable is available or not
main ()Treated like any other ordinary function, which can be called recursively

Given the static integer, it means static storage class is initialized once.

  • Static int var = 5
    • print 5
  • Then v- means decrease the value
  • Also check the var variable or not
  • If var value is available go to the main () function
  • All time same process will be continue till var is not empty
  • Printing 5 4 3 2 1

Question 7

Edit

Write in Short

Short Answer▾
  1. main()
  2. {
  3.     char ⚹p;
  4.     printf (“%d %d” sizeof (⚹p), sizeof (p));
  5. }

Explanation

Table Shows the Program
char ⚹ pp is the character pointer
printf ( “% d % d” sizeof (⚹ p) , sizeof (p) ) ;Sizeof (⚹ p) prints the pointed variable size and size of pointer respectively 1 and 2

So, print 1 2.

Developed by: