1) Base of hexadecimal number system? Answer : 16 2) Universal gate in digital logic? Answer : NAND 3) Memory type that is non-volatile? Answer : ROM 4) Basic building block of digital circuits? Answer : Gate 5) Device used for data storage in sequential circuits? Answer : Flip-flop 6) Architecture with shared memory for instructions and data? Answer : von Neumann 7) The smallest unit of data in computing? Answer : Bit 8) Unit that performs arithmetic operations in a CPU? Answer : ALU 9) Memory faster than main memory but smaller in size? Answer : Cache 10) System cycle that includes fetch, decode, and execute? Answer : Instruction 11) Type of circuit where output depends on present input only? Answer : Combinational 12) The binary equivalent of decimal 10? Answer : 1010 13) Memory used for high-speed temporary storage in a CPU? Answer : Register 14) Method of representing negative numbers in binary? Answer : Two's complement 15) Gate that inverts its input signal? Answer : NOT 16)
INPUT AND OUTPUT FUNCTIONS
The most fundamental operation in a C program is to accept input values from a standard input device and output the data produced by the program to a standard output device. we can assign values to variables using the assignment operator ‘=’. For example,
int a = 3;
What if we want to assign value to variable a that is inputted from the user at run-time? This is done by using the scanf function that reads data from the keyboard. Similarly, for outputting results ofthe program, printf function is used that sends results to a terminal. Like printf and scanf, there are different functions in C that can carry out the input–output operations. These functions are collectively known as Standard Input/ Output Library. A program that uses standard input/output functions must contain the following statement at the beginning of the program:
#include <stdio.h>
scanf()
The scanf()function is used to read formatted data from the keyboard. The syntax of the scanf() function can be given as,
scanf ("control string", arg1, arg2, arg3...argn);
The control string specifies the type and format of the data that has to be obtained from the keyboard and stored in the memory locations pointed by the arguments, arg1, arg2, ...,argn. The prototype of the control string can be given as,
%[*][width][modifier]type
* is an optional argument that suppresses assignment of the input field. That is, it indicates that data should be read from the stream but ignored (not stored in the memory location).
width is an optional argument that specifies the maximum number of characters to be read. However, if the scanf function encounters a white space or an unconvertible character, input is
terminated.
modifier is an optional argument (h, l, or L), which modifies the type specifier.
Modifier h is used for short int or unsigned short int, l is used for long int, unsigned long int, or double values. Finally, L is used for long double data values.
type specifies the type of data that has to be read. It also indicates how this data is expected to be read from the user. The type specifiers for scanf function are given Table : Type specifiers
Type Qualifying Input
%c For single characters
%d, %i For integer values
%e, %E,%f,%g,%G For floating point numbers
%o For octal numbers
%s For a sequence of (string of) characters
%u For unsigned integer values
%x,%X For hexadecimal values
The scanf function ignores any blank spaces, tabs, and newlines entered by the user. The function simply returns the number of input fields successfully scanned and stored.
As we have not studied functions till now, understanding scanf function in depth will be a bit difficult here, but for now just understand that the scanf function is used to store values in memory locations associated with variables. For this, the function should have the address of the variables. The address of the variable is denoted by an & sign followed by the name of the variable. Look at the following code that shows how we can input value in a variable of int data type:
int num;
scanf(" %4d ", &num);
The scanf function reads first four digits into the address or the memory location pointed by num.
printf()
The printf function is used to display information required by the user and also prints the values of the variables. Its syntax can be given as:
printf ("control string", arg1,arg2,arg3,...,argn);
After the control string, the function can have as many arguments as specified in the control string. The control string contains format specifiers which are arranged in the order so that they
correspond with the arguments in the variable list. It may also contain text to be printed such as instructions to the user, identifier names, or any other text to make the text readable.
Note that there must be enough arguments because if there are not enough arguments, then the result will be completely unpredictable. However, if by mistake you specify more number of
arguments, the excess arguments will simply be ignored. The prototype of the control string can be given as below:
%[flags][width][.precision][modifier]type
Each control string must begin with a % sign.
flags is an optional argument, which specifies output justification like decimal point, numerical sign, trailing zeros or octadecimal or hexadecimal prefixes. Below Table shows different types of flags with their descriptions.
Table : Flags in printf()
Flags Description
– Left–justify within the given field width
+ Displays the data with its numeric sign (either + or –)
# Used to provide additional specifiers like o, x, X, 0, 0x, or 0X for
octal and hexadecimal values respectively for values different than zero
0 The number is left–padded with zeroes (0) instead of spaces.
width is an optional argument which specifies the minimum number of positions that the output characters will occupy. If the number of output characters is smaller than the specified width, then the output would be right justified with blank spaces to the left. However, if the number of characters is greater than the specified width, then all the characters would be printed.
precision is an optional argument which specifies the number of digits to print after the decimal point or the number of characters to print from a string.
modifier field is same as given for scanf() function.
type is used to define the type and the interpretation of the value of the corresponding argument.
The type specifiers for printf function are given
The most simple printf statement is
printf ("Welcome to the world of C language");
The function when executed prompts the message enclosed in the quotation to be displayed on the screen.
For float x = 8900.768, the following examples show output under different format specifications:
printf ("%f", x) 8 9 0 0 . 7 6 8
printf("%10f", x); 8 9 0 0 . 7 6 8
printf("%9.2f", x); 8 9 0 0 . 7 7
printf("%6f", x); 8 9 0 0 . 7 6 8