google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.

Monday, July 28, 2014

Array based Qs and answers

1) What is an array?

Answer:-
An array is a group of data of the same data type stored in successive storage locations.



2)How are elements of an array accessed?

Answer:-
Elements of an array are accessed using subscripts.



3)What is a subscript?

Answer:-
A subscript or an index is a positive integer value that identifies the storage position of
an element in the array.



4)Which is the smallest subscript?

Answer:-
0 (zero)



5)How many subscripts does a one and two dimensional array have?

Answer:-
one dimensional array has one subscript and a two dimensional array has two
subscripts( row and a column subscript).



6)Write the syntax for declaring a one dimensional array.

Answer:-
syntax: datatype arrayname [size];



7) Write the syntax for declaring a two dimensional array.

Answer:-
Syntax: datatype arrayname [row size] [column size];



8) What do you mean by initializing an array?

Answer:-
Initializing of an array means storing data in to an array at the design time.



9) How one dimensional array is initialized?

Answer:-
The initialization can be done two ways –
• Initialization at design level- in this method of initialization the data values are
stored in to the array at the time of array declaration. 
Example: 
int a [0]={10,-50,20,300,5};
• Initialization at run time- to initialize an array at run time means to input data values
in to the array at the time of execution of the program.
Example:
int a[10];
for (i=0;i<10;i++)
scanf(“%d”,&a[i]);



10) How to output the elements of one dimensional array?

Answer:-
To print elements of an array a for loop is used.
Example:
int a[10];
for(i=0;i<10;i++)
printf(“%d\n”,a[i]);



11) How two dimensional arrays are initialized?

Answer:-
• initialization at design time- the data element are stored in to the array at the time
of declaration of the array. The elements of each row and each column are
represented within the pair of flower brackets.
Example : int a[3][3]={1,3,5,3,7,82,5,8};
• initialization of the array at the time of execution- to input data in to two
dimensional array, two for loops are used foe every value of the outer loop index.
The inner loop is executed a specified number of times.
Example: int a[4][5];
for(i=0;i<4;i++)
for(j=0;j<5;j++)
scanf(“%d”,&a[i][j]);



12) How do you print a matrix? Give ex.

Answer:-
A two dimensional array can be printed as follows-
int a[3][4];
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
printf(“%d\t”,a[i][j]);
}
printf(“\n”);
}





Unix based Qs and ans


1. What are the events done by the Kernel after a process is being swapped out from the main memory?

Answer :-
1.Kernel decrements the Reference Count of each region of the process. If the reference count becomes zero, swaps the region out of the main memory,
2.Kernel allocates the space for the swapping process in the swap device,
3.Kernel locks the other swapping process while the current swapping operation is going on,
4.The Kernel saves the swap address of the region in the region table.



2.Is the Process before and after the swap are the same? Give reason.

Answer :-
1.Process before swapping is residing in the primary memory in its original form. The regions (text, data and stack) may not be occupied fully by the process, there may be few empty slots in any of the regions and while swapping Kernel do not bother about the empty slots while swapping the process out.
2.After swapping the process resides in the swap (secondary memory) device. The regions swapped out will be present but only the occupied region slots but not the empty slots that were present before assigning.
3.While swapping the process once again into the main memory, the Kernel referring to the Process Memory Map, it assigns the main memory accordingly taking care of the empty slots in the regions.




3.What is Fork swap?

Answer :-
"fork()" is a system call to create a child process. When the parent process calls "fork()" system call, the child process is created and if there is short of memory then the child process is sent to the read-to-run state in the swap device, and return to the user state without swapping the parent process. When the memory will be available the child process will be swapped into the main memory.




4.What are the entities that are swapped out of the main memory while swapping the process out of the main memory?

Answer :-
1.All memory space occupied by the process, process's u-area, and Kernel stack are swapped out, theoretically.
2.Practically, if the process's u-area contains the Address Translation Tables for the process then Kernel implementations do not swap the u-area.




5.What is Expansion swap?

Answer :-
At the time when any process requires more memory than it is currently allocated, the Kernel performs Expansion swap. To do this Kernel reserves enough space in the swap device. Then the address translation mapping is adjusted for the new virtual address space but the physical memory is not allocated. At last Kernel swaps the process into the assigned space in the swap device. Later when the Kernel swaps the process into the main memory this assigns memory according to the new address translation mapping.




अच्छे विचार करे विचार

  पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...