Google Analytics

Saturday 17 September 2011

Wipro to develop saab's LEDS system


BANGALORE: Wipro Ltd has entered into an alliance with Saab AB to develop a market protective software for the Swedish major's Land Electronic Defence System (LEDS) in the country, the IT bellwether said.

LEDS provides protection to light and medium combat vehicles and main battle tanks against rocket-propelled grenades, anti-tank missiles, mortars and artillery shells.

"We will pursue opportunities for LEDS in the domestic market with Indian defence establishments and original equipment manufacturers," Wipro infrastructure engineering division president Pratik Kumar said on the margins of the Defence & Security Equipment International (DSEi) 2011 trade fair being held in London.

DSEi is the world's largest integrated defence and security exhibition providing a single platform to showcase the latest equipment and systems.

Wipro will develop, manufacture and integrate the equipment to address the Indian market for land-based active protection systems (APS).

"The primary objective of the partnership with Saab is to serve the Indian market with state-of-the-art APS solutions. The partnership will include component sourcing within the country, technology transfer and manufacture and integration of APS," Kumar said.

The global software major hopes the strategic alliance will put India on the global map as a cost-effective and reliable defence manufacturing hub.

Both the firms also partnered in 2008 and 2010 to address the Indian survivability technology market.

"India is an important market for us and a cornerstone of our global strategy. The new collaboration marks our next step towards consolidating our position in the Indian defense market," Saab's business head for LEDS Micael Johansson said on the occasion.

The e-warfare system combines active signature management and soft-kill and hard-kill mechanisms to provide full spectrum active protection to land vehicles. The specifications include hemispherical coverage to detect incoming threats and alert the crew.

Friday 19 August 2011

FRP UNIX Sample Questions with Answers


Sample Paper-1

1)Which of the following is true?
a)Shell is a process and runs like any user process
b)Shell is a built-in Kernel functionality
c)Shell is a wrapper for all the commands and utilities
d)None of the above

Answer : A.

2)Which is true with regards to the shell prompt
a)It can be accidentally erased with backspace
b)The prompt cannot be modified
c)The prompt can be customized (modified)
d)None of the above

Answer : C.

3)The /etc/passwd file contains
a)User account info
b)User id and password in encrypted form
c)Just the password of the user in encrypted form
d)None of the above

Answer : A.

4)User id 0 is
a)An innvalid user id
b)The id of the root user
c)The id of a user when the user's account is deleted
d)None of the above

Answer : B.

5)If a file is removed in Unix using 'rm' then
a)The file can be recovered by a normal user
b)The file cannot be recovered by a user
c)The file can be fully recovered provided the sytem is not rebooted
d)The file will be moved to /lost+found directory and can be recovered only by administrator's intervention

Answer :B.

6)Executing the 'cd ..' command when at the root level causes
a)Error message indicating the user can't access beyond the root level
b)Behavior is unix-flavor dependent
c)Results in changing to the 'home' directory
d)Nothing happens

Answer : D.

7)The login shell is
a)The shell program that runs when the user logs in
b)The shell program that authenticates the user while logging in
c)Common shell for all the users that belong to the same group
d)All of the above

Answer : A.

8)System calls are
a)The interface to the Kernel
b)Like any function call, implemented as part of the shell
c)Privileged calls that only superuser can make use of
d)None of the above

Answer :A.

9)Hidden files are
a)Those whose 'read' bit is set to 'h'
b)Permitted for (can be accessed) only superusers
c)Files that begin with a '.'
d)a & c

Answer : C.

10)Which of the following is true?
a)There is one superblock per system
b)There is one superblock per filesystem
c)There may be more than one superblock per filesystem ( non-redundant )
d)None of the above

Answer : B.
Description: In a typical unix file system, every filesystem has one superblock only. There may be a redundant superblock to protect against failures

11)A filename is modified using the command “mv filea fileb”, where fileb already exists. In this scenario, which of the following is true?
a)fileb’s inode number is changed to filea’s inode number
b)fileb’s inode number does not change, remains the same the old fileb
c)The inode entry for fileb is not affected by this command
d)None of the above

Answer :A.
Description:  fileb has the inode number that filea had earlier and the inode entry of fileb is released to the kernel.

12)Which of the following is true regarding inode number ?
a)Two files in a system may have the same inode number
b)Two files( non-linked) in a filesystem may have the same inode number
c)When a file is deleted, the inode is also deleted, the same inode number is not reused
d)None of the above

Answer :A.
Description: Inodes are unique within a filesystem, the kernel maintains the free inodes list and reallocates them when needed

13)A user creates a large data file ( ~ 1 MB size). Which of the following is true regarding the storage of this file on disk?
a)The file is stored in contiguous data disk blocks
b)The file is stored in disk blocks that are not contiguous, the disk blocks maintain the pointer to the next storage block
c)The inode information alone is not sufficient to identify all the disk blocks
d)The file is stored in disk blocks that may not be contiguous, the inode keeps track of where the data blocks are

Answer:D.
Description: The file is stored in disk data blocks that may not be contiguous, the details of these are stored in the inode addressing information

14)The ls –l output for /etc/passwd and /usr/bin/passwd is as follows:
-rw-rw-r--   1   root      root      2807    Apr 26  13:50   /etc/passwd
-r-s—x—x   1  root     root      17008  May 25  02:30 /usr/bin/passwd
If a user, not belonging to the group ‘root’, runs the passwd executable in an attempt to modify his password, then which of the following is true?
a)The passwd change fails since the user does not have permission to update the /etc/passwd file
b)The passwd change is successful because the program runs as root
c)The passwd change program runs in kernel mode where write access to the /etc/passwd file is possible
d)/etc/passwd is a special file and the system by default allows all users to update it

Answer:B.
Description: Since the setuid bit is set for /usr/bin/passwd, the program runs as root. Root has access to update the /etc/passwd file.

15)A user executes the following command successfully:
$ chmod +x file1.txt
Which of the following is true of the output of this command?
a)The command results in adding execute permission to the user who ran this command
b)The command results in adding execute permission for the owner of the file
c)The command results in an error since the file is not an executable file
d)The command results in adding execute permission for all users

Answer:D.
Description:This command can be run only by the owner of the file( or root), and it adds execute permission for all

16)The ls –al output on directory /home/user1/temp looks as follows:
$ cd /home/user1/temp
$ ls -al
-rw-rw-r--   1  user1     usrgrp  17008  May 25  02:30 .
-rw-rw-r--   1  user1     usrgrp  17008  May 25  02:30 ..
-r—r—r--   1  user1     usrgrp  17008  May 25  02:30 file1
$
If user1 executes the command “rm file1”, then which of the following is true?
a)The file is removed successfully ( and silently )
b)The rm command prompts for a confirmation, the command is successful upon confirmation
c)The rm command prompts for a confirmation, however the operation fails because of insufficient permissions
d)The rm command fails because of insufficient permissions

Answer:B.
Description: For deleting a file, directory write permission is sufficient, irrespective of file write permissions. The system prompts for user confirmation if there is no file write permission

17)A user creates a link to a file file1 using the following command “ln file1 file2”.Which of the following is true of a ls –ali output on this directory? The directory does not contain any other files or directories.
a)file1 and file2 have the same inode numbers
b)The number of links for file1 is displayed as 1
c)The number of links for the directory (.) is displayed as 3
d)a & c

Answer:A. Files that are hard—linked have the same inode number.The number of links field is 2 for both file1 and file2.The number of links displayed for the directory is not incremented because of the links created in files in the directory.

18)A user does a chmod operation on a file. Which of the following is true?
a)The last accessed time of file is updated
b)The last written time of file is updated
c)The inode access time of file is updated
d)a & c

Answer:C.
Description: The file contents are not accessed or updated, hence file access/write times are not updated. The permissions info is stored in the inode, hence the inode time is updated.

19)Look at the following code segment.
#include <stdio.h>
int numEntr = 5;
char c;
main()
{
     int i = 0;
     char *data;
      i = GetEntr();
      data = malloc ( sizeof(char) * i ));
       ….
       ….    
}
int GetEntr ()
{
         …………….
       ………..
}
Which of the following is true?
a)Variable numEntr is stored in the heap segment
b)Variable c, being uninitialized, is part of bss segment
c)Variable i is initialized and hence part of data segment
d)a & b

Answer:B.
Description: Initialized global data is stored as part of data segment;Local variables are stored on stack

20)The signal sent to a process when the Ctrl-C key is pressed is
a)KILL
b)TSTP
c)TERM
d)INT

Answer:D.

FRP Questions for practice


SampleQuestions-1
1.      main()
{
                   int a=10,*j;
          void *k;
                   j=k=&a;
          j++; 
                   k++;
          printf("\n %u %u ",j,k);
}



2.      Is this code legal?
int *ptr;
ptr = (int *) 0x400;

3.      void main()
{
int i=10, j=2;
int *ip= &i, *jp = &j;
int k = *ip/*jp;
printf(“%d”,k);
}       


4. void main()
{
printf(“sizeof (void *) = %d \n“, sizeof( void *));
          printf(“sizeof (int *)    = %d \n”, sizeof(int *));
          printf(“sizeof (double *)  = %d \n”, sizeof(double *));
          printf(“sizeof(struct unknown *) = %d \n”, sizeof(struct unknown *));
          }


5. void main()
{
int *i = 0x400;  // i points to the address 400
*i = 0;                  // set the value of memory location pointed by i;
}


6. What is the subtle error in the following code segment?
void fun(int n, int arr[])
{
int *p=0;
int i=0;
while(i++<n)
                   p = &arr[i];
*p = 0;
}


7. #include <stdio.h>
main()
{
char * str = "hello";
char * ptr = str;
char least = 127;
while (*ptr++)
                  least = (*ptr<least ) ?*ptr :least;
printf("%d",least);
}


8. main()
{
                   int i=300;
          char *ptr = &i;
                   *++ptr=2;
          printf("%d",i);
}


9. main()
{
                   int i = 258;
          int *iPtr = &i;
                   printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );
}       



10. main()
{
                   int i = 257;
          int *iPtr = &i;
                   printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );
}


11. main()
{
          static int a[3][3]={1,2,3,4,5,6,7,8,9};
          int i,j;
          static *p[]={a,a+1,a+2};
                   for(i=0;i<3;i++)
          {
                             for(j=0;j<3;j++)
                             printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j),
                             *(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i));
                   }
}


12. main()
{
                   char *p="GOOD";
          char a[ ]="GOOD";
printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p), sizeof(*p), strlen(p));
          printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a));
}


13. main()
{
                   int a=2,*f1,*f2;
          f1=f2=&a;
                   *f2+=*f2+=a+=2.5;
          printf("\n%d %d %d",a,*f1,*f2);
}


          14. 1. const char *a;
2. char* const a;
3. char const *a;
-Differentiate the above declarations.


15.    main()
{
char *p = “ayqm”;
char c;
c = ++*p++;
printf(“%c”,c);
}


16. main()
{       
char *p = “ayqm”;
printf(“%c”,++*(p++));
}


17. What is the output for the following program

          main()
                            {
      int arr2D[3][3];
       printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) );
               }


18. Is the following statement a declaration/definition. Find what does it mean?
int (*x)[10];


19. main()
{
          int a[10];
          printf("%d",*a+1-*a+3);
}


20. void main()
{
          void *v;
          int integer=2;
          int *i=&integer;
          v=i;
          printf("%d",(int*)*v);
}


21. # include <stdio.h>
int one_d[]={1,2,3};
main()
{
 int *ptr;
 ptr=one_d;
 ptr+=3;
 printf("%d",*ptr);
}


22. main()
{
 char *p;
 int *q;
 long *r;
 p=q=r=0;
 p++;
 q++;
 r++;
 printf("%p...%p...%p",p,q,r);
}


23. #include<stdio.h>
main()
{
  int a[2][2][2] = { {10,2,3,4}, {5,6,7,8}  };
  int *p,*q;
  p=&a[2][2][2];
  *q=***a;
  printf("%d..%d",*p,*q);
}


24. main()
          {
              int *j;
              {
               int i=10;
               j=&i;
               }
               printf("%d",*j);
}


25. main()
          {
          char *cptr,c;
          void *vptr,v;
          c=10;  v=0;
          cptr=&c; vptr=&v;
          printf("%c%v",c,v);
          }


26. main()
{
 int  i, n;
 char *x = “girl”;
 n = strlen(x);
 *x = x[n];
 for(i=0; i<n; ++i)
   {
printf(“%s\n”,x);
x++;
   }
 }


27. main ( )
{
 static char *s[ ]  = {“black”, “white”, “yellow”, “violet”};
 char **ptr[ ] = {s+3, s+2, s+1, s}, ***p;
 p = ptr;
 **++p;
 printf(“%s”,*--*++p + 3);
}


28. main( )
{
 void *vp;
 char ch = ‘g’, *cp = “goofy”;
 int j = 20;
 vp = &ch;
 printf(“%c”, *(char *)vp);
 vp = &j;
 printf(“%d”,*(int *)vp);
 vp = cp;
 printf(“%s”,(char *)vp + 3);
}


29. main( )
{
 char  *q;
 int  j;
 for (j=0; j<3; j++) scanf(“%s” ,(q+j));
 for (j=0; j<3; j++) printf(“%c” ,*(q+j));
 for (j=0; j<3; j++) printf(“%s” ,(q+j));
}


30. main( )
{
 static int  a[ ]   = {0,1,2,3,4};
 int  *p[ ] = {a,a+1,a+2,a+3,a+4};
 int  **ptr =  p;
 ptr++;
 printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);
 *ptr++;
 printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);
 *++ptr;
 printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);
 ++*ptr;
      printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);
}


31. main( )
{
  int a[ ] = {10,20,30,40,50},j,*p;
  for(j=0; j<5; j++)
    {
printf(“%d” ,*a);
a++;
    }
    p = a;
   for(j=0; j<5; j++)
      {
printf(“%d ” ,*p);
p++;
      }
 }


32. main( )
{
  int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
  printf(“%u %u %u %d \n”,a,*a,**a,***a);
       printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1);
      }


33. #include<stdio.h>
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8}  };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d----%d",*p,*q);
}



34. main()
{
           int c[ ]={2.8,3.4,4,6.7,5};
           int j,*p=c,*q=c;
           for(j=0;j<5;j++) {
                   printf(" %d ",*c);
                    ++q;   }
           for(j=0;j<5;j++){
printf(" %d ",*p);
++p;   }
}



35. void main()
{
          int  const * p=5;
          printf("%d",++(*p));
}




                             Answers
1. Answer:
                   Compiler error: Cannot increment a void pointer
Explanation:
Void pointers are generic pointers and they can be used only when the type is not known and as an intermediate address storage type. No pointer arithmetic can be done on it and you cannot apply indirection operator (*) on void pointers.


2. Answer:
                    Yes
Explanation:
The pointer ptr will point at the integer in the memory location 0x400.

3. Answer:
Compiler Error: “Unexpected end of file in comment started in line 5”.
Explanation:
The programmer intended to divide two integers, but by the “maximum munch” rule, the compiler treats the operator sequence / and * as /* which happens to be the starting of comment. To force what is intended by the programmer,
int k = *ip/ *jp; 
// give space explicity separating / and *
//or
int k = *ip/(*jp);
// put braces to force the intention 
will solve the problem. 


4. Answer  :
sizeof (void *) = 2
sizeof (int *)    = 2
sizeof (double *)  =  2
sizeof(struct unknown *) =  2
Explanation:
The pointer to any type is of same size.


5. Answer:
Undefined behavior
Explanation:
The second statement results in undefined behavior because it points to some location whose value may not be available for modification.  This type of pointer in which the non-availability of the implementation of the referenced location is known as 'incomplete type'.


6. Answer & Explanation:
If the body of the loop never executes p is assigned no address. So p remains NULL where *p =0 may result in problem (may rise to runtime error “NULL pointer assignment” and terminate the program).    


7. Answer:

Explanation:     
After ‘ptr’ reaches the end of the string the value pointed by ‘str’ is ‘\0’. So the value of ‘str’ is less than that of ‘least’. So the value of ‘least’ finally is 0.


8. Answer:
556
Explanation:
The integer value 300  in binary notation is: 00000001 00101100. It is  stored in memory (small-endian) as: 00101100 00000001. Result of the expression *++ptr = 2 makes the memory representation as: 00101100 00000010. So the integer corresponding to it  is  00000010 00101100 => 556.


9. Answer:
                   2 1
Explanation:
The integer value 257 can be represented in binary as, 00000001 00000001. Remember that the INTEL machines are ‘small-endian’ machines. Small-endian means that the lower order bytes are stored in the higher memory addresses and the higher order bytes are stored in lower addresses. The integer value 258 is stored in memory as: 00000001 00000010.  


10. Answer:
                   1 1
Explanation:
The integer value 257 is stored in the memory as, 00000001 00000001, so the individual bytes are taken by casting it to char * and get printed.


11. Answer:
                             1       1       1       1
                             2       4       2       4
                   3       7       3       7
                             4       2       4       2
                             5       5       5       5
                   6       8       6       8
                             7       3       7       3
                             8       6       8       6
                   9       9       9       9
Explanation:
                   *(*(p+i)+j) is equivalent to p[i][j].


12. Answer:
                   sizeof(p) = 2, sizeof(*p) = 1, strlen(p) = 4
          sizeof(a) = 5, strlen(a) = 4
Explanation:
                   sizeof(p) => sizeof(char*) => 2
          sizeof(*p) => sizeof(char) => 1
                   Similarly,
          sizeof(a) => size of the character array => 5
When sizeof operator is applied to an array it returns the sizeof the array and it is not the same as the sizeof the pointer variable. Here the sizeof(a) where a is the character array and the size of the array is 5 because the space necessary for the terminating NULL character should also be taken into account.


13. Answer:
16 16 16
Explanation:
f1 and f2 both refer to the same memory location a. So changes through f1 and f2 ultimately affects only the value of a.


14. Answer:
1. 'const' applies to char * rather than 'a' ( pointer to a constant char )
          *a='F'       : illegal
                             a="Hi"       : legal

2. 'const' applies to 'a'  rather than to the value of a (constant pointer to char )
          *a='F'       : legal
          a="Hi"       : illegal

3. Same as 1.


15. Answer:
b
Explanation:
There is no difference between the expression ++*(p++) and ++*p++. Parenthesis just works as a visual clue for the reader to see which expression is first evaluated.



16. Answer:
b      



17. Answer
1
Explanation
This is due to the close relation between the arrays and pointers. N dimensional arrays are made up of (N-1) dimensional arrays.  
          arr2D is made up of a 3 single arrays that contains 3 integers each .


arr2D



arr2D[1]




arr2D[2]


arr2D[3]






The name arr2D refers to the beginning of all the 3 arrays. *arr2D refers to the start of the first 1D array (of 3 integers) that is the same address as arr2D. So the expression (arr2D == *arr2D) is true (1).
Similarly, *arr2D is nothing but *(arr2D + 0), adding a zero doesn’t change the value/meaning. Again arr2D[0] is the another way of telling *(arr2D + 0). So the expression (*(arr2D + 0) == arr2D[0]) is true (1).
Since both parts of the expression evaluates to true the result is true(1) and the same is printed. 



18. Answer
                   Definition.
          x is a pointer to array of(size 10) integers.

                   Apply clock-wise rule to find the meaning of this definition.


19. Answer:
Explanation:
          *a and -*a cancels out. The result is as simple as 1 + 3 = 4 !     


20. Answer:
Compiler Error. We cannot apply indirection on type void*.
Explanation:
Void pointer is a generic pointer type. No pointer arithmetic can be done on it. Void pointers are normally used for,
Passing generic pointers to functions and returning such pointers.
As a intermediate pointer type.
Used when the exact pointer type will be known at a later point of time.


21. Answer:
garbage value
Explanation:
ptr pointer is pointing to out of the array range of one_d.


22.  Answer:
0001...0002...0004
Explanation:
++ operator  when applied to pointers increments address according to their corresponding data-types.


23. Answer:
garbagevalue..1
Explanation:
p=&a[2][2][2]  you declare only two 2D arrays. but you are trying to access the third 2D(which you are not declared) it will print garbage values. *q=***a starting address of a is assigned integer pointer. now q is pointing to starting address of a.if you print *q meAnswer:it will print first element of 3D array.


24. Answer:
10
Explanation:
The variable i is a block level variable and the visibility is inside that block only. But the lifetime of i is lifetime of the function so it lives upto the exit of main function. Since the i is still allocated space, *j prints the value stored in i since j points i.


25. Answer:
Compiler error (at line number 4): size of v is Unknown.
Explanation:
You can create a variable of type void * but not of type void, since void is an empty type. In the second line you are creating variable vptr of type void * and v of type void hence an error.



26. Answer:
(blank space)
irl
rl
l

Explanation:
Here a string (a pointer to char) is initialized with a value “girl”.  The strlen function returns the length of the string, thus n has a value 4. The next statement assigns value at the nth location (‘\0’) to the first location. Now the string becomes “\0irl” . Now the printf statement prints the string after each iteration it increments it starting position.  Loop starts from 0 to 4. The first time x[0] = ‘\0’ hence it prints nothing and pointer value is incremented. The second time it prints from x[1] i.e “irl” and the third time it prints “rl” and the last time it prints “l” and the loop terminates.


27. Answer:
          ck
Explanation:
In this problem we have an array of char pointers pointing to start of 4 strings. Then we have ptr which is a pointer to a pointer of type char and a variable p which is a pointer to a pointer to a pointer of type char. p hold the initial value of ptr, i.e. p = s+3. The next statement increment value in p by 1 , thus now value of p =  s+2. In the printf statement the expression is evaluated *++p causes gets value s+1 then the pre decrement is executed and we get s+1 – 1 = s . the indirection operator now gets the value from the array of s and adds 3 to the starting address. The string is printed starting from this position. Thus, the output is ‘ck’.


28. Answer:
          g20fy
Explanation:
Since a void pointer is used it can be type casted to any  other type pointer. vp = &ch  stores address of char ch and the next statement prints the value stored in vp after type casting it to the proper data type pointer. the output is ‘g’. Similarly  the output from second printf is ‘20’. The third printf statement type casts it to print the string from the 4th value hence the output is ‘fy’.


29. Explanation:
Here we have only one pointer to type char and since we take input in the same pointer thus we keep writing over in the same location, each time shifting the pointer value by 1. Suppose the inputs are MOUSE,  TRACK and VIRTUAL. Then for the first input suppose the pointer starts at location 100 then the input one is stored as
M
O
U
S
E
\0
When the second input is given the pointer is incremented as j value becomes 1, so the input is filled in memory starting from 101.
M
T
R
A
C
K
\0
The third input  starts filling from the location 102
M
T
V
I
R
T
U
A
L
\0
This is the final value stored .
The first printf prints the values at the position q, q+1 and q+2  = M T V
The second printf prints three strings starting from locations q, q+1, q+2
 i.e  MTVIRTUAL, TVIRTUAL and VIRTUAL.


30. Answer:
          111
          222
          333
          344
Explanation:
Let us consider the array and the two pointers with some address
a  

1
2
3
4
   100      102      104      106      108
                                                p
100
102
104
106
108
                                1000    1002    1004    1006    1008
          ptr        
1000
2000
After execution of the instruction ptr++ value in ptr becomes 1002, if scaling factor for integer is 2 bytes. Now ptr – p is value in ptr – starting location of array p, (1002 – 1000) / (scaling factor) = 1,  *ptr – a = value at address pointed by ptr – starting value of array a, 1002 has a value 102  so the value is (102 – 100)/(scaling factor) = 1,  **ptr is the value stored in the location pointed by  the pointer of ptr = value pointed by value pointed by 1002 = value pointed by 102 = 1. Hence the output of the firs printf is  1, 1, 1.
After execution of *ptr++ increments value of the value in ptr by scaling factor, so it becomes1004. Hence, the outputs for the second printf are ptr – p = 2, *ptr – a = 2, **ptr = 2.
After execution of *++ptr increments value of the value in ptr by scaling factor, so it becomes1004. Hence, the outputs for the third printf are ptr – p = 3, *ptr – a = 3, **ptr = 3.
After execution of ++*ptr value in ptr remains the same, the value pointed by the value is incremented by the scaling factor. So the value in array p at location 1006 changes from 106 10 108,. Hence, the outputs for the fourth printf are ptr – p = 1006 – 1000 = 3, *ptr – a = 108 – 100 = 4, **ptr = 4.


31. Answer:
Compiler error: lvalue required. 
                  
Explanation:
Error is in line with statement a++. The operand must be an lvalue and may be of any of scalar type for the any operator, array name only when subscripted is an lvalue. Simply array name is a non-modifiable lvalue.


32. Answer:
100, 100, 100, 2
114, 104, 102, 3
Explanation:
              The given array is a 3-D one. It can also be viewed as a 1-D array.

2
4
7
8
3
4
2
2
2
3
3
4
   100  102  104  106 108   110  112  114  116   118   120   122

thus, for the first printf statement a, *a, **a  give address of  first element . since the indirection ***a gives the value. Hence, the first line of the output.
for the second printf a+1 increases in the third dimension thus points to value at 114, *a+1 increments in second dimension thus points to 104, **a +1 increments the first dimension thus points to 102 and ***a+1 first gets the value at first location and then increments it by 1. Hence, the output.


33. Answer:
SomeGarbageValue---1
Explanation:
p=&a[2][2][2]  you declare only two 2D arrays, but you are trying to access the third 2D(which you are not declared) it will print garbage values. *q=***a starting address of a is assigned integer pointer. Now q is pointing to starting address of a. If you print *q, it will print first element of 3D array.


34. Answer:
                   2 2 2 2 2 2 3 4 6 5
          Explanation:
Initially pointer c is assigned to both p and q. In the first loop, since only q is incremented and not c , the value 2 will be printed 5 times. In second loop p itself is incremented. So the values 2 3 4 6 5 will be printed.


35. Answer:
                   Compiler error: Cannot modify a constant value.
Explanation:   
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".