.

.

Labels

Contributors

Showing posts with label C. Show all posts
Showing posts with label C. Show all posts

Friday, 12 October 2012

COMPUTER QUIZ

COMPUTER QUIZ
(To see correct answers, move mouse over options, answer will be highlighted)
1. Which of the following communication mode supports data transmission in
    both directions at the same time?   
  
    a) Simplex
    b) Duplex
    c) Half simplex
    d) Full duplex
    e) Multiplex

2. Which of the following transmission techniques let computer to
    alternatively send and receive data?

    a) Duplex
    b) Simplex
    c) Half duplex
    d) Full duplex
    e) None of above

3.  Modulation is the process of :
     a) Echoing every character that is received
     b) Converting digital signals to analog signals
     c) Converting analog signals to digital signals
     d) Sending a file from one computer to another computer
     e) None of above

4. A modem performs-
    a) Modulation
    b) Demodulation
    c) Data compression
    d) Both (a) & (b) 
    e) All (a), (b) & (c)

5. Which of the following keyboard format is most commonly used?
    a) TWRITER
    b) SPLITTER
    c) QWERTY
    d) Dvorak
    e) None of the above

6. The function of key F4 in a word processing application is -
    a) to repeat the last action
    b) to open a saved document
    c) to delete the highlighted text
    d) to open context menu of highlighted text
    e) None of above

7. Laser printer is an example of -
    a) Impact printer
    b) Inkjet printer
    c) Non-Impact printer
    d) Dot-matrix printer
    e) None of above

8. which of the following is a term related with scanners?
    a) Laser
    b) TWAIN
    c) QWERTY
    d) Media
    e) Cartridge

9. The resolution of a monitor depends on:
    a) Dot pitch of the monitor
    b) Number of bits representing a pixel
    c) Number of pixels that can be displayed
    d) Both (a) & (b)
    e) All (a), (b) & (c)

10. What does the term ISO stands for?
    a) Information System Output
    b) International Standards Organization
    c) International Systems organization
    d) Integrated Services Organization
    e) None of above
read more

Sunday, 16 September 2012

Sunday, 29 July 2012

Call by Value and Call by Reference


Call by Value and Call by Reference

In C programming language, variables can be referred differently depending on the context. For example, if you are writing a program for a low memory system, you may want to avoid copying larger sized types such as structs and arrays when passing them to functions. On the other hand, with data types like integers, there is no point in passing by reference when a pointer to an integer is the same size in memory as an integer itself.
Now, let us learn how variables can be passed in a C program.

Pass By Value

Passing a variable by value makes a copy of the variable before passing it onto a function. This means that if you try to modify the value inside a function, it will only have the modified value inside that function. One the function returns, the variable you passed it will have the same value it had before you passed it into the function.

Pass By Reference

There are two instances where a variable is passed by reference:
  1. When you modify the value of the passed variable locally and also the value of the variable in the calling function as well.
  2. To avoid making a copy of the variable for efficiency reasons.
Let's have a quick example that will illustrate both concepts.
xytotals.c:
Sample Code
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void printtotal(int total);
  5. void addxy(int x, int y, int total);
  6. void subxy(int x, int y, int *total);
  7.  
  8. void main() {
  9.  
  10.   int x, y, total;
  11.   x = 10;
  12.   y = 5;
  13.   total = 0;
  14.  
  15.   printtotal(total);
  16.   addxy(x, y, total);
  17.  
  18.   printtotal(total);
  19.  
  20.   subxy(x, y, &total);
  21.   printtotal(total);
  22. }
  23.  
  24. void printtotal(int total) {
  25.   printf("Total in Main: %dn", total);
  26. }
  27.  
  28. void addxy(int x, int y, int total) {
  29.   total = x + y;
  30.   printf("Total from inside addxy: %dn", total);
  31. }
  32.  
  33. void subxy(int x, int y, int *total) {
  34.   *total = x - y;
  35.   printf("Total from inside subxy: %dn", *total);
  36. }



Here is the output:
There are three functions in the above program. In the first two functions variable is passed by value, but in the third function, the variable `total` is passed to it by reference. This is identified by the “*” operator in its declaration.
The program prints the value of variable `total` from the main function before any operations have been performed. It has 0 in the output as expected.
Then we pass the variables by value the 2nd function addxy, it receives a copy of `x``y`, and `total`. The value of `total` from inside that function after adding x and y together is 15.
Notice that once addxy has exited and we print `total` again its value remains 0 even though we passed it from the main function. This is because when a variable is passed by value, the function works on a copy of that value. They were two different `total` variables in memory simultaneously. The one we set to 15 in the addxy function, was removed from memory once the addxy function finished executing.  However, the original variable `total` remains 0 when we print its value from main.
Now we subtract y from x using the subxy function. This time we pass variable `total` by reference (using the “address of” operator (&)) to the subxy function.
Note how we use the dereference operator “*” to get the value of total inside the function. This is necessary, because you want the value in variable `total`, not the address of variable `total` that was passed in.
Now we print the value of variable `total` from main again after the subxy function finishes. We get a value of 5, which matches the value of total printed from inside of subxy function.  The reason is because by passing a variabletotal by reference we did not make a copy of the variable `total` instead we passed the address in memory of the same variable `total` used in the function main. In other words we only had one total variable during entire code execution time.
read more