Computer Programming question-GE6151

download Computer Programming question-GE6151

of 56

description

Computer Programming question, GE6151 Computer Programming question, Ist year cp question bank, anna univ computer programming question bank, prepared by g. prempaul, KLNCE Madurai

Transcript of Computer Programming question-GE6151

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    1

    UNIT I Short Questions

    Generation and Classification of Computers- Basic Organization of a

    Computer

    1) List the four parts of a complete computer system.

    (i) Hardware (ii) software (iii) data (iv) users

    2) What are the advantages and disadvantages of I generation computers?

    Advantages: These were the fastest at their time. They were able to execute

    complex calculations in an efficient manner.

    Disadvantages: operations depended on machine language. Therefore, they

    are not very easy to program. They were not flexible for many different

    application. They were bulky and produced lot of heat.

    3) Give the advantages and disadvantages of II generation computers.

    Advantage: they were the fastest at that time. Used assembly language so

    programming was easier. They could be transported from one place to other.

    Disadvantages: They were required to be placed in air-conditioned rooms.

    The cost of these computers were so high that home users cannot afford to

    buy. They were only special purpose computers and so, they can not be used

    for general purpose applications. 4) Give the advantages and disadvantages of III generation computers.

    Advantages: fastest at their time. Computational time was greatly reduced

    and thus very productive. There were easily transportable. They could be

    installed easily and occupied less space. They were used both business and

    scientific application and thus there were considered general purpose

    computers.

    Disadvantages: storage capacity was not high. Overall cost was high. They

    were still to be placed in air-conditioned rooms.

    5) Give the advantages and disadvantages of IV generation computers.

    Advantages: The use of VLSI technology made these computers powerful in

    speed and accuracy. Storage capacity was very high. They were highly

    reliable and required less maintenance. They were highly user friendly.

    Programs used were highly portable to different computers and they are very

    versatile. They require less power to operate.

    Disadvantage: very complicated mechanism is needed to assemble these

    computers. Working on these computers depends on the instructions given by

    the programmer.

    AdministratorTypewritten TextPREMPAUL .G KLNCE MADURAI

    AdministratorTypewritten Text

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    2

    6) Mention the advantages and of V generation computers over IV.

    Advantages: Development of Personal Digital Assistant(PDAs). Parallel

    processors. Invention of Optical disk technology. Development of internet.

    The users of these computers find it very comfortable to use because of

    several additional multimedia features.

    7) Mention the advantages and of VI generation computers over V

    Advantages: Development of Personal Digital Assistant(PDAs). Parallel

    processors. Invention of Optical disk technology. Development of internet.

    The users of these computers find it very comfortable to use because of

    several additional multimedia features.

    8) Differentiate between analog and digital computers.

    Analog Digital

    The data is represented in the form

    of electrical pulses. Data is stored in terms of 0s and 1s.

    The electronic circuit employed in

    the analog computer is an

    operational amplifier.

    This consists of ALU, control unit, a

    memory unit and I/O units.

    9) Mention the various types of computers according to their size and

    capability. Microcomputers

    Minicomputers

    Mainframe computers

    Super computers 10) Mention the different categories of computers made for individual users. a) Desktop computers

    b) Workstations

    c) Notebook computers

    d) Tablet computers

    e) Handheld computers

    f) Smart phones

    11) List out the difference between mainframe computers and super computer.

    Mainframe Computer: Used by large business organisation employing very

    huge applications such as financial transaction processing, consumer

    statistics, enterprise resource planning. The term refers to huge cabinet with a

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    3

    central processor and a huge main memory.

    Super Computers: It is the fastest type of computers that can perform

    complex operations at a very high speed. They are used for (i) weather

    forecasting (ii) Graphics animations (iii) Nuclear energy establishments (iv)

    petroleum exploration. Super computers employ the fastest processors and

    they are large in number very large memory and storage is being used. Many

    optimising techniques to enhance the performance of the processor by

    pipeling and parallelism methods.

    12) Draw the block diagram of a computer.

    13) Distinguish between RAM and ROM. RAM: As new data is entered into the computer, it is also stored in

    memory- but only temporarily. Data is both written to and read from this

    memory. RAM is volatile, meaning that it loses its contents when the

    computer is shut off or if there is a power failure.

    ROM: It permanently stores its data, even when the computer is shut off.

    ROM is called non-volatile memory because it never loses its contents.

    ROM holds instructions that the computer needs to operate.

    Number Systems - Binary Decimal Conversion 14) What is the weight of the digit 6 in each of the following decimal

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    4

    numbers?

    (a) 1386 (b) 54,692 (c) 671,920 Ans: (a) 6 (b) 600 (c) 15) Express each of the following decimal numbers as a power of ten:

    (a) 10 (b) 100 (c) 10,000 (d) 1,000,000 Ans: (c) 1104 + 0103 + 0102 + 0101 + 0100 16) Give the value of each digit in the following decimal numbers:

    (a) 471 (b) 9356 (c) 125,000 Ans: (b) 9 9000 , 3 300 , 5 50, 6 - 6 17) How high can you count with four decimal digits? 9999

    18) Convert the following binary numbers to decimal:

    (a) 1110 (b) 1010 (c) 11100 (d) 10000 (e) 10101 Ans (e) 21 19) Convert the following binary numbers to decimal:

    (a) 110011.11 (b) 101010.01 (c) 1000001.111 Ans: (c) For decimal 1 26 + 0 25 + ...+ 1 = 65 for fractional:

    1 2-1 + 1 2-2 + 1 2-3. Thus 65.875 20) What is the highest decimal number that can be represented by each of

    the following numbers of binary digits (bits)?

    (a) two (b) three (c) four (d) five (e) six

    ans: (b) 7(23 1)

    21) How many bits are required to represent the following decimal numbers?

    (a) 17 (b) 35 (c) 49 (d) 68 (e) 81 Ans: (c) 49 = 110001 so minimum 6 bits are needed. 22) Generate the binary sequence for each decimal sequence:

    (a) 0 through 7 (b) 8 through 15 (c) 16 through 31 Ans: (b) 1000,1001,1010,1011,1100,1101,1110,1111

    Decimal-to-Binary Conversion 23) Convert each decimal number to binary(by using the sum-of-weights

    method):

    (a) 10 (b) 17 (c) 24 (d) 48 (e) 61

    Ans: (c) 24 = 16 + 8 = 124 + 12

    3 + 02

    2 + 02

    1 + 02

    0 so 24 = 110002

    24) Convert each decimal fraction to binary using repeated multiplication by

    2 method

    (a) 0.98 (b) 0.347 (c) 0.9028

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    5

    Ans: (b) 0.3472=0.694; 0.6942=1.388; .3882=0.776;

    0.7762=1.552; 0.5522=1.104 and so on.

    So, approximately, 0.347 = .01011 25) Convert each decimal fraction into binary by using the sum-of-weights

    method:

    (a) 0.32 (b) 0.246 (c) 0.0981 Binary Arithmetic

    26) Add the binary numbers:

    (a) 11 + 01 (b) 10 + 10 (c) 101 + 11 (d) 111 + 110 (e) 1001 + 101 (f)

    1101 + 1011

    27) Perform the following binary multiplications:

    (a) 11 11 (b) 100 10 (c) 111 101 1's and 2's Complements of Binary Numbers 28) Determine the l's complement of each binary number:

    (a) 101 (b) 110 (c) 1010 Ans: (a) 010 (b) 001 (c) 0101 29) Determine the 2's complement of each binary number using either

    method:

    (a) 10 (b) 111 (c) 1001 (d) 1101 Ans: (a) 10 (b) 001 (c) 0111 (d) 0011

    Signed Numbers 30) Express each decimal number in binary as an 8-bit sign-magnitude

    number:

    (a) +29 (b) -85 (c) + 100 (d) -123 Ans: (a) 00011101 (b) 10101011 (c) 01100100 (d) 10000101 31) Express each decimal number as an 8-bit number in the l's complement

    form:

    (a)-34 (b) +57 (c) -99 (d) +115 Ans: (a) 11011101 (b) 00111001 (c) 10011100 32) Determine the decimal value of each signed binary number in the 2's

    complement form:

    (a) 10011001 (b) 01110100 (c) 10111111 Ans: (a) -103 (b) +116 (c) -65

    Arithmetic Operations with Signed Numbers 33) Convert each pair of decimal numbers to binary and add using the 2's

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    6

    complement form:

    (a) 33 and 15 (b) 56 and -27and 25 (c) -110 and -84 Ans: 2s complement of 33 = 00100001+

    2s complement of 15 = 00001111

    00110000 48

    2s complement of 56 = 00111000

    2s complement of -27 = 11100101

    00011101(no end carry) 29

    2s complement of 25 = 00011001

    Result = 00110110 54

    Hexadecimal Numbers 34) Convert each hexadecimal number to binary:

    (a) 3816 (b) 5916 (c) A1416 (d) 5C816 Ans: (a) 11 1000 0001 0110 (d) 0101 1100 1000 0001 0110 35) Convert each binary number to hexadecimal:

    (a)1110 (b) 10 ans: (a) E (b) 2 36) Convert each octal number to decimal:

    (a) 128 (b) 278 (c) 568 (d) 648 (e) 1038

    Ans: (a) 10 (c) 46 (d) 52 (e) 67

    37) Convert each octal number to binary:

    (a) 138 (b) 578 (c) 1018 (d) 3218 (e) 5408 Ans: (a) 001 011 (b) 101 111 (c) 001000001 (e) 101 100 000 38) Convert each binary number to octal:

    (a) 111 (b) 10 (c) 110111 (d) 101010 Ans: (a) 7 (b) 2 (c) 67 (d) 52 39) Convert each of the following decimal numbers to 8421 BCD:

    (a) 10 (b) 13 (c) 156 (d) 21 (e) 25 Ans: (a) 0001 0000 (c) 0001 0101 0110 (e) 0010 0101 40) Convert each of the BCD numbers to decimal:

    (a) 10000000 (b) 001000110111 Ans: (a) 80 (b) 237

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    7

    41) Convert each pair of decimal numbers to BCD, and add as indicated:

    (a) 28 + 23 (b) 65 + 58 (c) 113 + 101 (d) 295 + 157 Ans: (a) 28 in BCD = 0010 1000

    23 in BCD = 0010 0011

    0100 1011 > 9 So add 6

    Carry 0001 0110

    0101 0001 51 is the result. 42) Convert each binary number to Gray code:

    (a)10011 (b) 11011

    Ans: (a) 11010 (b) 10110

    43) Convert the Gray code to binary

    (a) 1011 (b) 11010 Ans: (a) 1101 (b) 10011

    Problems. Need for logical analysis and thinking

    44) What are the three steps in solving a problem? (i) Understand the problem (ii) Find the connection between the data and

    the unknown devise a plan(iii) carry out the plan and examine the solution obtained.(iv) look back check if there are more approaches.

    45) State the purpose of problem solving through computers. Computers are very fast in solving problems. The Computer calculates with

    great accuracy. A Computer produces results without any error. A repetitive

    calculation is performed with the same accuracy for any number of times in a

    Computer. That is why Computers are used in solving problems.

    46) Give a formal definition for a program.

    An assault on large problems employs a succession of programs. These

    programs are rife with issues that appear to be particular to the problem at

    hand.

    47) Name the four paradigms of programming. (i) Unstructured programming (ii).Structured programming and

    (iii)Object Oriented programming (iv) Aspect Oriented programming

    48) Mention the types of programming languages. (i) Machine language

    (ii) Assembly language

    (iii) High-level language

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    8

    49) State the requirements for solving problem by computers.

    To appreciate programming an as an intellectual activity in its own right,

    we must turn to Computer programming. We must read and write

    computer programs many of them. 50) Name the different aspects of problem solving. It is widely recognised that problem-solving is a creative process which

    largely defies systematization and mechanization. This may not sound

    very encouraging to the would-be problem-solver. To balance this, most

    people, during their schooling, acquire at least a modest set of problem-

    solving skills which they may or may not be aware of. Within this

    context, then, where can we begin to say anything useful about computer

    problem-solving? We must start from the premise that computer problem-

    solving is about understanding.

    51) What are the primary strategies of problem solving? (i) Understanding of the problem. (ii) Developing a design strategy.

    (iii) Planning the development process.

    52) Illustrate the idea behind the top-down-design approach. Top-down design is a strategy that we can apply to take the solution of a

    computer problem from a vague outline to a precisely defined algorithm

    and program implementation. Top-down design provides us with a way

    of handling the inherent logical complexity and detail frequently

    encountered in computer algorithms. It allows us to build our solutions to

    a problem in a stepwise fashion. 53) Mention the steps in bottom up design with an illustration. In a bottom-up approach, the individual base elements of the system are

    first specified in great detail. These elements are then linked together to

    form larger subsystems, which then in turn are linked, sometimes in many

    levels, until a complete top-level system is formed. This strategy often

    resembles a "seed" model, whereby the beginnings are small, but

    eventually grow in complexity and completeness. Object-oriented

    programming (OOP) is a paradigm that uses "objects" to design

    applications and computer programs.

    Algorithm, Flowcharts and pseudocode

    54) Define the term algorithm. List the characteristics of a good algorithm.

    An algorithm is defined as a finite sequence of explicit instructions that,

    when provided with a set of input values, produces an output and then

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    9

    terminates. An algorithm must have no ambiguity. There should not be

    any uncertainty about the next instruction execution. It should terminate

    in a finite number of steps.

    55) What is meant by computational complexity of an algorithm?

    It is the execution time of the algorithm in terms of its input parameters.

    56) Explain the advantages of an algorithm. A good algorithm helps the programmer to design the program in an

    easier manner. 57) Define the term pseudo-code. Pseudocode is not the actual name but it models and may even look like

    programming code. It is the generic way of describing an algorithm

    without using any programming language related notations. Or, more

    simply it is the outline of the program, written in a form that can be easily

    converted into real programming statements. 58) Give the advantages and limitations of flowchart. Advantages: it makes the logic clear and visual. It communicates the

    interconnection of the logical system. The problem can be well analysed.

    Useful for coding the problem. Testing and debugging is easily done.

    Flowcharts are good programming documentation for future reference.

    Disadvantages: it is complicated. It is costly and difficult to modify in

    future and no updates are easy to do.

    59) Give the advantages and limitations of pseudocode. Advantages: it is language independent. It is easier to develop program

    from pseudocode than from flowchart. It is very compact than a

    flowchart. 60) What are the three basic program control structures? Sequence, selection and repetition.

    UNIT I BIG QUESTIONS

    1) Explain the evolution of Computers 8

    2) Explain the different computer generations. 8

    3) Explain the classification of computer in detail. 8

    4) With a block diagram explain computer organization. 8

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    10

    5) Explain briefly about (a) Mainframe computers

    (b) Super computers

    8

    6) Explain about the various characteristics of a Computer. 8

    7) Explain the various types of computer memory. 8

    8) Convert 6245.118 into its decimal equivalent 6

    9) Perform the following subtraction: 68-47 and 47-68 in 1s and

    2s complement method.

    12

    10) Illustrate the process of addition and subtraction in 1s and 2s

    complement system with suitable examples

    8

    11) With examples illustrate the conversion of Decimal to Binary,

    Octal and Hexadecimal numbers.

    8

    12) Convert 39.77 into binary. 4

    13) Convert 1011.1101 to octal, hex and decimal. 6

    14) Convert 1723.256 to Hex. 6

    15) Add 39 & 93 using BCD addition method. 8

    16) Explain in detail about (i) EBCDIC (ii) ASCII

    (iii) UNICODE

    8

    17) Describe the basic steps in the system development life cycle. 5

    18) What documentation should a programmer receive to be able

    to write a program?

    6

    19) List and explain the steps that a programmer follows in

    writing a program?

    5

    20) What are the three tools the programmer uses to develop a

    program solution?

    3

    21) Define an algorithm. List the characteristics of a good

    algorithm. 6

    22) Draw a flow-chart to multiply two matrices. 8

    23) Write a algorithm to multiply two matrices. 8

    24) Write a pseudocode to multiply two matrices. 6

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    11

    25) Write an algorithm to compute the factorial of a number 8

    26) Define a flow-chart. List the advantages of using a flowchart. 5

    27) Draw a flow-chart to find the highest of marks in a set of n

    marks.

    8

    28) What are the advantages of using a pseudo-code? 5

    29) Write a pseudo-code to add two matrices. 8

    30) Discuss the three basic program control structures with

    suitable examples.

    6

    31) Explain the features of a good programming language. 8

    32) Describe the characteristics of programming languages. 8

    33) Explain the top-down and the bottom-up approaches in

    program development.

    8

    34) What are the advantages of structured programming? 6

    35) What is the difference between black-box and white-box testing?

    8

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    12

    UNIT II

    Introduction to C programming fundamentals structure of a C program

    1) Why is C language called middle-level language?

    C combines the features of high-level language and functionality like

    assembly language. It reduces the gap between high-level language and

    low-level language, that is why it is known as middle level language.

    2) What are the functions of an interpreter and a compiler?

    An interpreter reads only one line of the source program at a time and converts

    into object codes. In case of errors, the same may be indicated instantly. The

    compiler reads the entire program and converts it to the object code. It

    provides errors not of one line but errors of entire program.

    3) Write the rules for writing a C program.

    a) All statements should be written in lower case. Upper case letters are

    used only for symbolic constants.

    b) Blank spaces may be inserted between words. This improves the

    readability of the statements. But it is not used while declaring a

    variable, keyword and constant and functions.

    c) It is not necessary to fix the position of statements in the program,

    that is the programmer can write the statement anywhere between the

    two braces following the declaration part. The user can also write

    one or more statements in one line by separating a semicolon (;)

    between them.

    d) The opening and closing braces should be balanced.

    4) Elaborate different sections of C program.

    a. Include or header file section

    b. Global declaration.

    c. Function main.

    d. Declaration section.

    e. Executable part.

    f. User-defined function.

    g. Comments

    5) What is the role of ( {}) curly braces in C program?

    The program execution starts from the opening brace ({) and ends with

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    13

    the closing brace (}). Between these two braces the program should

    declare the declaration and executable part

    6) What is meant by compilation? Explain in detail.

    The source program statements should be translated to object programs

    which is suitable for execution by the computer. The translation is done

    after correcting every statement. If there is no error, the compilation

    proceeds and translated program are stored in another file with same file

    name with extension .obj. if any errors are there, the programmer should correct them. Linking is also an essential process. It puts all other

    program file and functions together that are required by the program.

    7) Briefly explain the functions of a linker.

    After the program has been translated into object code, it is ready to be

    linked. This process is once again performed automatically whenever the

    cc or gcc command is issued under Unix. The purpose of the linking

    phase is to get the program into a final form for execution on the

    computer. If the program uses other programs that were previously

    processed by the compiler, then during this phase the programs are linked

    together. Programs that are used from the systems program library are also searched and linked together with the object program during this

    phase. These are the functions of the linker.

    8) What are the different standard data types?

    There are only four standard data type available in C.

    char specifies a character variable

    int specifies an integer variable

    float specifies a floating-point variable

    void associates function returning no value

    9) What are the differences between signed and unsigned data types?

    Signed integer

    Unsigned integer

    Signed integer occupies 2 bytes

    in memory

    Occupies 2 bytes in memory

    Range : -32,768 to 32,767 Range : 0 to 65535

    Format specifier is %d or %i Format specifier is %u

    By default signed int is short By default unsigned int is

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    14

    signed int short unsigned int

    Constants, Identifiers, variables and data types

    10) What is meant by a variable and a constant?

    In a declaration, which consists of type, variable(one or more variables

    are declared after the type, separated by commas) and delimited with a

    semicolon. Moreover, during the type declaration, the variables so

    declared, may be assigned with some corresponding values which has the

    following format:

    type variable = expression;

    There are four basic types of constants in C. They are integer constants,

    floating-point-constants, character-constants, and string-constants.

    11) What are the C keywords? Elaborate them.

    The following words are called reserved words or keywords and may not

    be used by the user.

    auto double int struct

    break else long switch

    case enum register typedef

    char extern return union

    const float short unsigned

    continue for signed void

    default goto sizeof volatile

    do if static while

    12) List the rules for declaring a variable.

    13) What are identifiers?

    An identifier is a sequence of letters or digits that is, a..z or A..Z or 1..9.

    The underscore is an identifier. Identifiers have 31 characters which are

    significant and some time more characters are considered to be

    significant. Internal identifiers are preprocessor macro names. An

    external identifier starting with an underscore is reserved for the C

    library.

    1. First character must be alphabetic character or underscore. 2. Must consist only of alphabetic characters, digits, or underscores. 3. First 31 characters of an identifier are significant. 4. It can not duplicate a reserved word(as described before)

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    15

    14) Explain the methods for initialization of variables.

    variable-name = constant;

    Or

    [= ];

    15) Write about space requirement for variables of different data types.

    Data type Size(byte)

    char 1

    unsigned char 1

    int 2

    unsigned int 2

    long 4

    float 4

    double 8

    16) What are delimiters? Explain their uses.

    Language pattern of C uses special kind of symbols that are terminals in

    nature, which are called delimiters.

    Delimiters Use

    : colon Useful for label

    ; semicolon Terminates statement

    ( ) parenthesis Used in expression and functions

    [] square

    brackets Used in array declarations

    {} curly braces Scope of statement

    # hash Pre-processor directive

    , Comma Variable separator

    17) List any three keywords with their use.

    Operators and expression, Simple input and output functions

    18) What is the difference between %f and %g format specifiers? Can both be

    used representing float numbers?

    %f is decimal point format where as %g is a scientific format using exp

    fields.

    19) What do you mean by type conversion? Why is it necessary?

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    16

    Implicit type conversion and Promotional hierarchy:

    char short int unsigned int long int u

    l int float double long double

    So, when char and float are added, result will be a float. Similarly, if a

    long is added with a double, the result will be a double according to the

    promotional hierarchy, available.

    Explicit type conversions

    Cast. By having a unary operator called cast, we can convert the integer

    to a float.

    20) Explain different types of operators available in C.

    Types of operator Symbolic representation

    Arithmetic operator +, - , *, /, and %

    Relational operator >,=,>,

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    17

    where the numerical constant, variable or expression is preceded by a minus

    sign. Note that the unary operator minus is distinctly different from the

    arithmetic operator which denotes subtraction(-). The subtraction operator

    obviously requires two separate operands.

    23) Describe logical operators with their return values.

    Operator Meaning

    && AND

    | | OR

    These are referred as logical AND and logical OR, respectively.

    Suppose that i is an integer variable with value 3 and c is a character

    variable with value 'w' and f is a floating point variable with value 3.56.

    Several complex logical expressions that make use of these variables is

    shown below.

    The first expression is false because, the first operand is false. Where as

    in the second expression, the second operand is false but the first operand

    makes it effectively true. In the third expression, both the operands are

    true.

    Expression Interpretation Return

    Value

    (i 34) False 0

    (c >= 56) | | (i == 4) True 1

    (c != 'x') && (f == 3.56) true 1

    24) Distinguish between logical and bitwise operators.

    Logical operators return either true or false where as bitwise operator returns

    the result of the operation.

    25) What are relational operators?

    There are four relational operators in C. They are

    Operator Meaning

    >= greater than or equal to

    > greater than

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    18

    Closely associated with the relational operators, there are two equality

    operators.

    Operator Meaning

    == equal to

    != not equal to

    26) What is the difference between '=' and '=='?

    = is an assignment operator and the other one is an equality operator.

    27) What are the symbols used for a) OR b) AND c) XOR d) NOT operations.

    OR - | |, AND - &&, XOR - ^, NOT - !

    28) Explain the precedence and associativity of operators in arithmetic

    operations.

    Precedence is used to determine the order in which different operators in a

    complex expression are evaluated.

    Associativity is used to determine the order in which operators with the same

    precedence are evaluated in a complex expression.

    29) List the operators from higher priority to least priority.

    Highest to the lowest

    1 Primary ( )

    2 Postfix ( ), [ ],->, ++, --

    3 Unary ++,--, sizeof, +, -, &, *, ~,( )

    4 Binary *,%,/,+,-,, =, ==,!=, &,^,|,&&,||

    5 Ternary ?:

    6 Assignment =, +=, -+, *=, /=, %=, >>=,

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    19

    97(decimal) and z 122(decimal ASCII).

    32) What are the formatted and unformatted I/O functions?

    printf(),scanf() known as formatted I/O functions and

    getchar(),putchar(),gets(),puts() functions are known to be

    unformatted I/O functions.

    33) What is the difference between character I/O and string I/O?

    Character I/O: Consider the function getchar(). This function reads the

    character type data from the standard input. It reads one character at a time

    and till the user presses the enter key. Similarly in putchar()function, it

    prints one character on the screen at a time, which is read by the standard

    input.

    String I/O: Consider the function gets( ). This

    function is used for accepting any string through stdin(keyboard) until

    enter key is pressed. The header file stdio.h is needed for

    implementing the above function. Similarly puts() prints the string or

    the character array.

    34) What are the escape sequences?

    An escape sequence like \n provides a general and extensible mechanism for

    representing hard-to-type or invisible characters. Theyre summarised in the table below

    Escape sequence Character

    \a alert(bell)

    \b backspace

    \f formfeed

    \n newline

    \r carriage return

    \t horizontal tab

    \v vertical tab

    \\ backslash

    \? question mark

    \' single quote

    \" double quote

    \ooo octal number

    \xhh hexadecimal number

    \0 null

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    20

    35) Write a C program to print the following pattern:

    0

    1 0 1

    2 1 0 1 2

    Program

    #include

    #include

    main()

    {

    int a,b,c,d;

    clrscr();

    printf(%5d\n,0);

    printf(%6d\n,101);

    printf(%7d,21012);

    getch();

    }

    Output

    0

    101

    21012

    Decision Making - Branching and Looping

    36) Is it possible to use multiple default statements in switch() statement?

    No

    37) Write the use of else and default statements in if-else and switch( )

    statements respectively.

    In the if-else structure which is known to be 2-way selection, takes care

    of true as well as false conditions. It has two blocks one block is for if

    statement and it is executed when the condition is true. The other block is for

    else statement and it is executed when the condition is false.

    In the switch( ) statements, the default is executed if none other

    values of the case labels satisfy the value of the switch( ) constant.

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    21

    38) Why goto statement is avoided?

    It is learnt that the goto statement may let a programming language abused.

    Since in practice, it is always possible and easy to write code without goto

    statements, the goto statements are avoided in view of good programming

    practice.

    39) Why break statement is essential in switch( ) statement? Which other

    functions or keywords can be used in place of the break statement.

    The break statement causes control to be transferred out of the switch

    statement, thus preventing more than one group of statements from being

    executed.

    40) Is it possible to use else statement in place of default or vice versa?

    No

    41) Can we put default statement anywhere in the switch () case structure?

    Yes. But as usual, the break statement is necessary to by-pass to other

    case labels.

    52) What are the limitations of switch() case statement?

    Every time when a case label matches, the corresponding case block is

    executed. In the case-block a break statement is necessary to exit the

    switch which is a limitation.

    43) What is a loop? Why it is necessary in the program?

    The concept of a loop is to do an action repeatedly over and over again.

    Generally the loop dont stop. We want our program to end when the work is

    done. To make sure that the work is done, we have a condition that controls

    the loop. We must design the loop in such a way that before and/or after each

    iteration, it checks to see if it is done. If it is not, it repeats one more time.

    The loops are classified as counter controlled and event controlled loops.

    44) What happens if you create a loop that never ends?

    The program never terminates without any user intervention.

    45) Is it possible to create a for loop that is never executed?

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    22

    Yes. If the pre-test condition is false, the loop is never executed.

    46) Is it possible to nest while loop within for loops?

    Yes

    47) What is the difference between (!0) and (!1)? How while loop works with

    these values?

    Actually !0 is 1 and !1 is a 0.

    48) What is the difference between (1= =!1) and (1!=1) ?

    !1 evaluates to 0 so (1==!1) will become (1==0) which is false so, (1==!1)

    evaluates to 0. Similarly, in the expression, (1!=1), both lhs and rhs of the !=

    operator are the same. So the expression will evaluate to false and its value

    would be 0. Though the return the same value of 0, they have different

    evaluation sequence.

    UNIT II Part B Questions

    1) Explain the different types of operators available in C 8

    2) What are constants? Explain the various types of constants available in C

    8

    3) Mention the use of break and continue statements 4

    4) Explain the program control structures with examples. 6

    5) What is meant by operator precedence? Discuss its impact in programming with suitable examples.

    8

    6) Explain how switch statement differ from if statement. 5

    7) Write a C program to print the given number in reverse. 6

    8) Explain any two constructs used for decision making, branching and looping statement. Give an example and explain the working of the

    construct.

    16

    9) Write a C program to evaluate the following series

    8

    10) Write a program in C to check if the given number is prime. 8

    11) Write a C program to check whether the given number is palindrome or not.

    8

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    23

    12) Write a C program t generate Fibonacci series upto 200. 8

    13) Write a program in C to represent the number of years represented by an integer into the following units of time:

    a) Minutes

    b) Hours

    c) Days

    d) Months

    e) Seconds.

    Use switch( ) statement. State the assumption made in your problem.

    16

    14) Write the syntax of for construct in C with suitable examples. 4

    15) Write a C program to determine the number of and sum of all integers between 100 and 200 which are divisible by 7.

    8

    UNIT III

    Part A Questions and answers

    Arrays Initialization, Declaration, One dimensional and Two dimensional arrays

    1) Mention the advantages and limitations of arrays

    Advantages: while analysing a huge size of data, all of them will not be

    of sequence or integers. So indexing these data will help processing

    better and this idea can be extended to multi-dimension.

    Disadvantages: The memory size for an array can not be altered after

    compile time(they are static in nature) so expanding or contracting the

    array size at run time is a big problem in limiting the size of the program.

    So by considering the worst cases only the size of the array is decided so

    flexibility of program-size with respect to small and big amount of data is

    not possible in C.

    2) What is the relation between an array name and an element number? How are elements referred using base addresses?

    Let us consider the following program segment:

    int a[5]={1,2,3,4,5};

    printf(Base address=%u and its value=%d\n,a,a[0]); printf(second address=%u and its value=%d\n,a+1,a[1]);

    printf(fifth position address=%u value=%d\n,a+4,a[4]);

    here, first printf will correspond to printing the base address of the array

    under consideration and its value which is 1.

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    24

    Output:

    Base address=2345624 and its value=1

    second address=2345628 and its value=2

    fifth position address=2345640 and its value=5

    The elements can be referred using a dereferencing operator *. That is

    *(a+1) is the content of the address of a+1 which corresponds to the second

    array position.

    3) An array name contains base address of the array. Can we change the base address of the array?

    No. it is done by the compiler usually at runtime.

    4) Can we store values and addresses in the same array? Explain.

    No. Here the value at an array address may not accommodate a pointer.

    Probably if we have an array of pointers we can do that.

    5) Mention the difference between character array and integer array.

    Character array Integer array

    Each array position occupies

    single byte.

    It occupies two bytes

    A special case of a character array

    is called a string which is

    terminated by a \0 character

    No such cases exist

    6) How does an ordinary variable differ from an array definition?

    An ordinary variable will have one value corresponding to it. But an array

    can have different values assigned at various positions of its index

    7) Give the syntax of declaring a two-dimensional array.

    storage-class arrayname[expression1][expression2];

    Storage-class is an optional field. Every arrayname associates with a

    data-type. expression1 and expression2 are positive valued integer

    expressions.

    8) Explain multi dimensional array.

    The C program allows array of two or multi dimensions. The compiler

    determines the restriction on it. The syntax of multi-dimensional array is as

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    25

    follows. arrayname [S1][ S2][ S3]...[ Sn]; where, Si is the size of the ith

    dimension. Few examples are, int mat[ 3][ 3]; int marks [3][3];

    A linear indexing formula for multi-dimensional arrays that are declared as

    such, e.g. by int A[10][20] or int A[m][n]

    Strings- String operations String Arrays

    9) What are strings? How are they declared?

    Character arrays terminated by \0 are called strings. Strings are normally used to manipulate the text such as words and sentences.

    For example

    char name[ ] = INDIA;

    10) What is NULL character? Why is it important?

    The NULL character \0 is the terminal character in a string array.

    11) Is it possible to initialize NULL character in the string?

    The last character in a string array is the NULL character so if the last

    character in a character array is not a NULL character and if it is initialised

    with a NULL character then that character array will become a string array.

    12) Mention some standard string functions available in C.

    char*strcat(s,ct) concatenates source string ct to end of s

    returns s.

    size_t strlen(cs) Determines the length of a string

    char *strcpy(s,ct) Copy string ct to string s return s. Pad

    with '0' if ct has fewer than n characters

    int strcmp(cs, ct) compare string cs to string ct,

    return ct.

    In the above table, variables s and t are of type char *; cs and ct are of

    type const char *; n is of type size_t; and c is an int converted to

    char.

    13) Why is it necessary to count NULL character while declaring string?

    Because the total count determines the number of array indices used to

    store the particular string.

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    26

    14) What is the difference between the functions strcmp( ) and strncmp()?

    strncmp(s,t,n) is the same as strcmp(s,t) but it compares only

    the first n characters.

    15) What is the difference between NULL, '\0' and 0?

    \0 is the escape sequence in the format specification. 0 is the corresponding ASCII code for the NULL character. NULL is the name in

    which it is interpreted in English in reference to C language.

    Sorting Searching and Matrix Operations

    16) Name the different sorting techniques available.

    Shell sort, quick sort, insertion sort, radix sort and bubble sort.

    17) Give the algorithm for bubble-sort

    Let a[0],a[1],...,a[n-1] be an array declared and initialised in C. The

    bubble-sort algorithm can be shown as below:

    1 for i = 0 to n-1

    2 for j= n-1 downto i + 1

    3 if a[j] < a[j - 1]

    4 exchange a[j] with a[j-1]

    Line 3 in the above algorithm will execute n-1 number of times and in the

    first loop and n-2 times in the second loop and so on. Thus, totally the

    comparison(line 3) will occur

    (n-1)+(n-2)+(n-3)+...+3+2+1 = times.

    18) Mention the need for searching program with an example.

    In many situations there is requirement of finding a particular

    data/element among a large collection of data. So there must be some

    method to locate whether or not the desired data is present in a list at

    shortest time becomes important. Search algorithms are designed for such

    purposes. Example: voter information.

    19) Distinguish between linear search and binary search.

    Linear search is done on an unordered list where as the binary search is

    done on an ordered list. Binary search is more efficient.

    20) Mention the advantages of quick sort over selection sort.

    The quick sort is supposed to perform better than selection sort in a large

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    27

    run.

    Unit III Part B Questions

    1) Explain the need for array variables. With respect to arrays, describe the following: declaration of arrays, Two-dimensional array and

    accessing an array element.

    8

    2) Write a C program to add and subtract two matrices. 8

    3) Explain the need for array variables. With respect to arrays, describe the following: declaration of arrays, Two-dimensional array and

    accessing an array element

    8

    4) Write a C program to find the largest and the smallest number in a given array

    8

    5) Write a program that calculates the average of an array of 10 floating-point values.

    5

    6) Write a C program to sort a given set of numbers in ascending order. 8

    7) Write a C program to count letters in a sequence of characters 8

    8) Discuss about any eight built-in string/other library functions 8

    UNIT IV

    Part A Questions and answers

    Function definition of function Declaration of function, pass by value, pass by reference

    1) Write the definition of a function. Indicate the types of functions available in C.

    data-type name(type-1 arg-1, type-2 arg-2, , type-n arg-n)

    where data-type represents the data type of the item that is

    returned by the function, name represents the function name, and type-

    1, type-2 type-n represent the data type of the arg-1, arg-

    2,, arg-n respectively. The data types are assumed to be of type int

    if they are not shown explicitly. However the omission of the data types

    is considered poor programming practice, even if the data items are

    integers.

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    28

    2) How do functions help to reduce the program size?

    There are several advantages to modular approach to program

    development. For example, many programs require that a particular

    group of instruction be accessed repeatedly from several different places

    within the program. The repeated instruction can be placed within a

    single function, which can then be accessed or whenever it is needed.

    Moreover a different set of data can be transferred to the function each

    time it is accessed. Thus, the use of a function is to avoid the need of

    redundant(repeated) programming of the same instruction.

    3) Differentiate between library and the user-defined functions

    Library functions User defined functions

    These are predefined set of

    functions

    Defined by the user according

    to requirement

    The task is limited The user understands the

    scope of the function so that

    the ideas may be implemented

    in the best way.

    4) How does a function work? Explain how arguments are passed and results are returned?

    Once a function is defined and called, it takes some data from the calling

    function and returns a value to the called function.

    The detail of inner working of function is unknown to the rest of the

    program. Whenever a function is called, control passes to the called

    function and the working of the calling function is stopped. When the

    execution of the called function is completed, control returns back to the

    calling function and executes the next statement.

    The values of the actual arguments passed by the calling function are

    received by the formal arguments of the called function. The number and

    type of the actual and formal arguments must be the same. Any

    mismatch will produce unexpected result.

    The function operates on formal arguments and sends back the result to

    the calling function. The return() statement performs this task.

    5) List any five-library functions and illustrate them with suitable examples.

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    29

    float pow(float,float);

    The above is the proto type for power function where the first argument

    is raised to second power. That is xy where x is first and y is second

    argument. z = pow(4.0,5.0);

    Will cause z to have 1024.0 assigned. In other words, the above

    statement returns the value 1024.0 to the calling module. //void strcat(char *,char *);

    char x=abc,y=def;

    printf(%s,strcat(x,y));

    will cause abcdef to be printed on the screen.

    6) What are actual and formal arguments?

    Actual arguments are the parameters of the calling module. Formal

    arguments are the parameters of the called module.

    7) What is the purpose of return () statement?

    This helps function in sending back the results to the calling module.

    8) What does it mean if there is no return statement in the function?

    Functions without return statement is not wrong if the function return a

    void type otherwise, an error message will be displayed by the compiler.

    9) What are void functions?

    They return no value to the calling module.

    10) Why is it possible to use the same variable names for actual and formal arguments?

    In the called module however new local variables are created every time

    a function is called(except the function has reference parameters)

    11) What is main () function in C? Why is it necessary in each program?

    This is what is first invoked by the compiler to further proceed.

    12) Explain the different formats of return ( ) statements. How many values does return statement return at each call?

    The return statement can be used in the following ways:

    1. return(expression); Here expression value is returned to the

    calling function and if expression is omitted return simply transfers

    control to the calling function. 2. There may be one or two return

    statements in a function. They may be executed according to the

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    30

    condition arising in a program.

    13) What is a global pointer? Illustrate with a suitable example.

    Normally pointers addresses declared outside a function are referred as

    global pointers with respect to the called functions. Consider:

    main(){

    int a=3,b=4;

    swap(&a,&b);

    printf(a=%d b=%d,a,b);

    }

    void swap(int *m,int *n){

    int temp;

    temp = *m;

    *m = *n;

    *n = temp;

    }

    In the above code snippet, the function swap has an argument which is

    of type pointer to an integer, passed on to the function which is global

    with respect to the function swap.

    14) Why is return statement not necessary when function is called by reference?

    The reference parameters are transparent to the calling module so the

    changes made by the function will automatically become visible to the

    calling module upon a successful return of the called function.

    15) Distinguish between function prototype and function definition(code)?

    Function prototype is the function declaration where as the function

    definition is the actual content of the function statements return values

    etc..

    16) Does the function prototype match with the function definition?

    Yes.

    17) Can we define a user-defined function with the same library function name?

    No; but if the header file is not included for the particular program, the

    function name will not conflict so it is allowed only in such occasion.

    18) List and explain the four scope of variables in brief.

    Automatic variables(local variables), External variables, Static variables

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    31

    and Register variables

    19) What are automatic/local variables?

    These are defined inside a function. A variable declared inside a function

    without a storage class name, by default is an auto variable. The scope of

    the variable is local to the block in which they are defined. These

    variables are available only to the current block or program. Once the

    execution of the function takes place and return turns off function, the

    contents and the existence of the auto variables or local variables vanish.

    20) Distinguish between static and external variables?

    Static variable External variable

    The static may be of internal

    or external type, depending

    upon where it is declared

    External variables are

    declared outside the function

    body.

    It is initialised only once. If both external and auto

    variables are declared with

    the same name in a program,

    the first priority is given to

    auto variable.

    The value of static variable

    persists on each call and the

    last change made remains

    throughout the program

    execution.

    21) Can we declare a variable in different scopes with different data types? Answer in detail

    22) What is calling by reference in C?

    In this method, the addresses of the actual arguments are passed to the

    formal parameters of the function.

    23) Give an example for a function returning a pointer

    The following function gets an integer between 1 and 12 and returns the

    pointer to month name.

    /* month_name: return name of n-th month */

    char *month_name(int n)

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    32

    {

    static char *name[] = {

    "Illegal month",

    "January", "February", "March",

    "April", "May", "June",

    "July", "August", "September",

    "October", "November", "December"

    }

    return(n < 1 || n > 12)?name[0]:name[n];

    In the above function the variable name is a static array of character

    pointers. The initializer is a list of character strings; each is assigned to the

    corresponding position in the array. The characters of the i-th string are

    placed somewhere, and a pointer to them is stored in name[i]. Since the

    size of the array name is not specified, the compiler counts the initializers

    and fills in the correct number

    Pointers definition, initialization

    24) What are pointers? Why are they important?

    Other language have pointers but few uses them so freely, with such

    abandon, as C does. And why not? It's C's clever use of pointers that

    makes it the excellent systems language.

    25) Explain the use of (*) indirection operator.

    (*)s operand is the address of a value stored in memory, and it returns the value stored in that address.

    The example below shows that:

    void main()

    {

    int alpha = 1;

    printf("The value %d is stored at address%u.\n",alpha,&alpha);

    printf("The value %d is stored at address%u.\n",*(&alpha),&alpha);

    }

    the output is

    The value 1 is stored at address 9364.

    The value 1 is stored at address 9364.

    after execution.

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    33

    The expression alpha - that is, the name alpha by itself - and the

    expression *(&alpha) do exactly the same thing: both cause C to

    return the value stored at the address associated with the name alpha. The

    expression &alpha returns alpha's address, and *(&alpha) returns the

    value stored at that address.

    26) Explain the effect of ++ and -- operator with pointer of all data types.

    Consider the following program

    #include

    void main ()

    {

    float *ptr;

    static float zilch[] = {1.23,2.34,3.45,4.56,5.67,0.0};

    ptr = zilch;

    while (*ptr != 0.0)

    {

    printf("The value stored at address %u is %f\n",ptr,*ptr);

    ptr++;

    }

    }

    The output would be

    The value stored at address 4144 is 1.230000

    The value stored at address 4148 is 2.340000

    The value stored at address 4152 is 3.450000

    The value stored at address 4156 is 4.560000

    The value stored at address 4160 is 5.670000

    Note the intervals between the address now. They are each 4. Our

    references computer addresses its memory byte by byte, and an int

    takes up two bytes where as a float uses four. The same case applies to

    operator as well.

    27) Explain the relation between an array and a pointer.

    Consider the declarion:

    int prime[4]={2,3,5,7},*ap;

    Here prime[0] refers to 2 prime[1] refers to 3 and so on. But simply, prime

    will mean a pointer to the number 2 in the above declaration. By having an

    assignment as

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    34

    ap = prime;

    will initialise the pointer variable ap to point to the first position of the array

    we have just declared and initialised above. Also a statement like

    ap++;

    will increment the value of the pointer variable ap to point to the next

    position of the array that is prime[1]. This is the relationship between

    array and a pointer.

    28) Which are the possible arithmetic operations with pointers?

    int array[5]; /* Declares 5 contiguous integers */

    int *ptr = array; /* Arrays can be used as pointers */

    ptr[0] = 1; /* Pointers can be indexed with array syntax */

    *(array + 1) = 2; /* Arrays can be dereferenced with pointer */

    *(1 + array) = 3; /* Pointer addition is commutative */

    2[array] = 4; /* Subscript operator is commutative */

    This allocates a block of five integers and names the block array, which acts

    as a pointer to the block.

    Unit IV Part B Questions

    1) Write a C program using user defined function to sort numbers in ascending order.

    6

    2) Write note on storage classes in C. 6

    3) How can a function return a pointer to its calling function? 6

    4) Explain in detail how an array can be passed as an argument in a user defined function. Illustrate your answer with an example

    program.

    8

    5) What are the advantages of using pointers? How are pointers declared and initialised? How the value of the variable is accessed

    using pointers? Give examples.

    8

    6) Give an example of a C function which can swap two integer variables on a return.

    8

    7) Write a C program to copy one string to another and count the number of characters copied.

    8

    8) Write an algorithm and a C program to print prime numbers lesser 10

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    35

    than 500.

    1) What is a structure in C? How is a structure declared? A structure is a collection of one or more variables, possibly of different

    types, grouped together under a single name for convenient handling.

    Structures help to organize complicated data, particularly in large

    programs, because they permit a group of related variables to be treated as

    a unit instead of as separate entities.

    struct tag{

    Member1;

    Member 2;

    ...

    Member m;

    };

    In this declaration struct is a required keyword; tag is the name that

    identifies this type; member 1, member 2 ... member m are

    individual member declarations. 2) How are structure elements stored in memory?

    Consider the declaration shown next page:

    struct student

    {

    char name[30];

    int rollno;

    float height;

    };

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    36

    studnt1

    struct studnt1 student;

    The above declaration creates variables studnt1 of structure type

    student and it reserves a total of 36 bytes(30 for the name[30], 2

    bytes for the rollno which is an integer and 4 bytes for float

    height)

    3) Explain nested structure.

    We can take any data type for declaring structure members like int,

    float, char, and so on. In the same way, we can also take object of

    one structure as members in another structure. Thus, structure within

    structure can be used to create complex data applications. See below

    struct date

    {

    int dd;

    int mm;

    int yyyy;

    };

    struct employee

    {

    char name[30];

    struct dob date;

    struct doj date;

    };

    struct cseemp employee;

    name[30]

    rollno

    height

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    37

    The above example shows how structure within structure is declared and it

    can be visualised as follows:

    4) What are aggregate types? The structure is a kind of aggregate data type in C which is nothing but a derived data type.

    5) Can a structure have a pointer to itself? Consider the following declaration for a node in a binary tree. Let us say the

    node has a value which is of type integer and as it is a binary tree a node may

    have two pointers pointing to two other nodes. This can be represented as:

    struct *node

    {

    int value;

    struct node *child1,*child2;

    }

    6) How is the declaration struct type{...}; different from typedef struct {...};? By using typedef we can create new data type. The statement typedef

    cse_emp

    name[30]

    dob

    dd

    mm

    yyyy

    doj

    dd

    mm

    yyyy

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    38

    is to be used while defining the new data type. The syntax is as given below:

    typedef type dataname;

    Here, type is the data type and dataname is the user-defined name for that

    type.

    typedef int hours;

    Here, hours is another name for int and now we can use hours instead of int

    in the declaration as given below:

    typedef int hours;

    hours hrs;

    7) How to keep track of which field of a union is in use? In C it is not possible to know what type is currently stored in union.

    8) What are the differences between a symbolic constant and an enumeration constant?

    enumeration constant symbolic constant

    Enumerations are unique types that

    have integral values; associated with

    each enumeration is a set of named

    constants. Enumerations behave like

    integers, but it is common for a

    compiler to issue a warning when an

    object of a particular enumeration is

    assigned something other than one

    of its constants, or an expression of

    its type.

    Example:

    enum months {JAN=1, FEB,

    MAR, APR, MAY, JUN, JUL, AUG,

    SEP, OCT, NOV, DEC};

    Now the value of MAY would be 5 but

    if we say

    enum months {JAN, FEB, MAR,

    APR=100, MAY, JUN, JUL,

    AUG, SEP, OCT, NOV, DEC};

    the value of MAY would be 101 but the

    value of JAN would be 0

    A #define line defines a

    symbolic name or symbolic

    constant to be a particular string

    of characters:

    #define name replacement list

    Example:

    #define MAX 100

    9) What are the various stages a program undergoes before execution?

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    39

    The various stages a program undergoes before execution are:

    1.Translation 2.Loading

    The various parts of translation are:

    1.Preprocessing 2.Compilation 3.Linking

    10) What is a macro? What are object like macros and function like macros?

    Preprocessor directives such as # define are used at the beginning of the C

    program to define constants or any macro substitution.

    #define

    // The above one is an object-like macro

    #define ()

    // The above is a function-like macro, note parameters

    The function-like macro declaration must not have any whitespace

    between the identifier and the first, opening, parenthesis. If whitespace is

    present, the macro will be interpreted as object-like with everything

    starting from the first parenthesis added to the token list. 11) What is the role of the error directive?

    #error "Pl. specify build type in the Makefile"

    When the preprocessor hits the #error directive, it will report the string

    as an error message and halt compilation; what exactly the error message

    looks like depends on the compiler. 12) What is the role of the pragma directive?

    Source Program

    Source Libraries

    (.obj Files)

    Simplified C Program

    Object Code(.obj File)

    Relocatable executable

    Code (.exe File)

    Address binding and

    execution

    Preprocessor

    Linker

    Loading

    Translation Compiler

    Loader

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    40

    The #pragma directive is the method specified by the C standard for providing additional information to the compiler, beyond what is

    conveyed in the language itself. An unrecognised pragma is ignored by

    the compiler.

    UNIT V Big Questions 1) What is a structure? How does a structure differ from an array? 6 2) How an array of structure is initialised? 6 3) How a structure member is accessed? 6 4) Explain about structures and unions with suitable examples. 6 5) Write short notes on Pre-processor directives 6 6) Define a structure with tag population with fields Men and

    Women. Create structure within structure using state and

    population structure. Read and display the data.

    8

    7) Write a C program to define structure with tag state, with fields

    state name, number of districts and total population. Read and

    display the data.

    8

    8) Write a C program to accept records of 20 states using array of

    structures. The structure should contain name of the state and

    number of engineering colleges, medical colleges, management

    colleges, science colleges. Calculate and display the total colleges

    in each state which is having the highest number of colleges

    16

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    41

    Last 5 Anna University Question Papers

    (GE2112(R-2008 3 questions Papers) and

    GE6151(R-2013 2 question Papers)

    Reg. No:

    Question Paper Code : 11432

    B.E./B.Tech. DEGREE EXAMINATIONS, JANUARY 2013

    First Semester

    (Common to all Branches)

    GE 2112/CS 1610(8)0230001- FUNDAMENTALS OF COMPUTING AND

    PROGRAMMING

    Time : Three hours Maximum: 100 Marks

    Answer ALL questions

    PART A -- (10 x 2 = 20 Marks)

    1. Give the classification of computers.

    2. Convert the (756)10 to octal and hexa decimal

    3. What are the various types of softwa-re?

    4. What is a protocol?

    5. What is a pseudocode?

    6. Define: algorithm.

    7. Write any four escape sequences in 'C'.

    (8). Distinguish between while .....and do...while statement.

    9. What is a pointer?

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    42

    10. Write any four features of arrays.

    PART B -- (5 16 = (8)0 Marks)

    11.

    a) i) Explain the characteristics of computers. (8)

    ii) Discuss the evolution of computers. (8)

    (OR)

    b) Explain the basic organisation of computer with suitable block

    diagram.

    (16)

    12.

    a) Explain the steps of software developments with suitable examples. (16)

    (OR)

    b)

    i) Discuss the following internet terminologies:

    (1) Band width

    (2) FTP

    (3) IP Address

    (4) Modem.

    (8)

    ii) Write some of the internet applications. (8)

    13. a)

    i) Draw the flowchart for finding the roots of a quadratic

    equation

    (8)

    ii) Write an algorithm to find the largest of three numbers. (8)

    (OR)

    b) i) Discuss in detail about the features of office packages. (16)

    14. a) i) Explain different data types in 'C' with examples. (8)

    ii) Discuss about bitwise operators and logical operators in 'C'. (8)

    (OR)

    b)

    i) Explain any four format string with examples. (4)

    ii) Write the syntax of "for construct" in C. Give an example. (4)

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    43

    iii) Write a C program to count the letters in a sequence of

    characters

    (8)

    15. a) i) Write a C program to sort the given set o~numbers in

    ascending order

    (16)

    ii) Discuss about any eight built-in functions.

    (OR)

    b) i) Write the syntax of structure declaration in 'C' program. Give

    an example

    (4)

    ii) Distinguish between structure and union. (4)

    iii) Write-a C program to find the addition of two matrices. (8)

    -----------------------

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    44

    Reg. No:

    Question Paper Code : 21466

    B.E./B.Tech. DEGREE EXAMINATIONS, MAY/JUNE 2013

    First Semester

    (Common to all Branches)

    GE 2112/CS 1610(8)0230001- FUNDAMENTALS OF COMPUTING AND

    PROGRAMMING

    Time : Three hours Maximum: 100 Marks

    Answer ALL questions

    PART A -- (10 x 2 = 20 Marks)

    1. Distinguish between analog and digital computer.,

    2. Find the decimal equivalent of the binary number (10110011)2.

    3. What are the types of web browsers?

    4. List some of the internet applications.

    5. What is an algorithm?

    6. What are the advantages of flowchart?

    7. Name the basic data types used in C.

    8. What are the various I/O functions in C?

    9. What is an array?

    10. How is pointer variables initialized?

    PART B -- (5 16 = (8)0 Marks)

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    45

    11

    .

    a) i) Explain the various generations of computers. (10)

    ii) Briefly explain the characteristics of a computer. (6)

    (OR)

    b) i) Draw the block diagram of a computer and explain. (10)

    ii) Convert the decimal number 698.125 into the binary and octal

    equivalent.

    (6)

    12

    .

    a) i) Explain about the types of software. (10)

    ii) Write about URL (6)

    (OR)

    b)

    i) Discuss the software development steps. (10)

    ii) Explain the common types of internet connections. (6)

    13

    .

    a)

    i) Explain the features ofMicrosoft Word. (10)

    ii) Draw a flowchart to find the largest of three numbers. (6)

    (OR)

    b) i) Discuss the features of Microsoft Excel. (16)

    ii) What is pseudo code? Explain its guidelines and benefits.

    14

    .

    a) i) Explain the different types of operators available in C. (8)

    ii) Write a C program to evaluate the following series:

    (8)

    (OR)

    b) i) What are constants? Explain the various types of constants in

    C.

    (8)

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    46

    ii) Write a C program to find the number of and sum of all

    integers greater than 100 and less than 200 that are divisible by

    7

    (8)

    15

    .

    a) i) Write a C program to find sum of the diagonal elements of a

    matrix.

    (16)

    ii) Write a C program to count the number of words in a string

    using pointers.

    (OR)

    b) i) Explain the various storage classes in C. (8)

    ii) Write a C program to exchange the values of two variables

    using function.

    (8)

    -------

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    47

    Reg. No:

    Question Paper Code : 11432

    B.E./B.Tech. DEGREE EXAMINATIONS, MAY/JUNE 2014

    First Semester

    Civil Engineering

    GE 2112/CS 1610(8)0230001- FUNDAMENTALS OF COMPUTING AND

    PROGRAMMING

    (Common to All Branches)

    (Regulation 2008)

    Time : Three hours Maximum: 100 Marks

    Answer ALL questions

    PART A -- (10 2 = 20 Marks)

    1. List any two important characteristics of computers.

    2. List some of the key hardware and software technologies of fifth generation

    computers.

    3. How will you convert a binary number to a gray code? What is the gray code

    equivalent of 110011?

    4. What do you mean by system software? Give examples.

    5. Differentiate between Internet and World Wide Web.

    6. What are the protocols used for mail transfer?

    7. List any two characteristics and two advantages of pseudo code.

    8. Illustrate the structure. of a C program.

    9. State any twe-library functions for string handling and their purpose.

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    48

    10. List any two preprocessor directives in C.

    PART B -- (5 16 = 80 Marks)

    11

    .

    a) What do you mean by Computer generations? Discuss in detail

    about all the generations of computer

    (16)

    (OR)

    b) i) Subtract 1010110 from 1101101 using 2's complement

    method.

    (5)

    ii) Subtract 153 from 277 using 10's complement method. (5)

    iii) Convert the binary number 101011110011 to hexadecimal

    number.

    (3)

    iv) Convert the octal number 45732 into its binary equivalent (3)

    12

    .

    a) i) List the different types of software. Explain and give

    examples.

    (8)

    ii) Define the terms compiler, preprocessor, interpreter,

    assembler.

    (8)

    (OR)

    b)

    Discuss about:

    (1) Electronic Mail

    (2) HTTP

    (3) FTP

    (4) Usenet

    (16)

    13

    .

    a)

    Discuss about algorithm, flowchart and pseudo code and elaborate

    their role while writing a program. Write an algorithm, draw a

    flowchart and write pseudoco for the problem of generating the

    triangular number sequence. 1,3,6,10,15,21,28,36,45,...[Given the

    value of the nth

    term = n*(n+1)/2]

    (8)

    (OR)

    b) i) Explain about word processing- software and presentation

    software in detail.

    (16)

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    49

    14

    .

    a) Discuss about the need and different types of looping statements in

    C. Illustrate through examples.

    (8)

    (OR)

    b) Discuss about the need and different types of branching statements

    in C. Illustrate through. examples

    (8)

    15

    .

    a) Differentiate between the following concepts andI give example for each.

    i) Structure and union (8)

    ii) Call by reference and Call by value. (8)

    (OR)

    b)

    i) Discuss about functions in C. (4)

    ii) Write a C function to calculate the fastcrial of a given number

    and use it in the main program to calculate the binomial

    coefficient of a given number. Given binomial coefficient

    (12)

    -----------

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    50

    Reg. No:

    Question Paper Code : 11432

    B.E./B.Tech. DEGREE EXAMINATIONS, JANUARY 2014

    First Semester

    (Common to all Branches)

    GE 6151 COMPUTER PROGRAMMING

    (Regulation 2013)

    Time : Three hours Maximum: 100 Marks

    Answer ALL questions

    PART A -- (10 x 2 = 20 Marks)

    1. List some important hardware and software technologies of fifth generation

    computers.

    2. Write two characteristics of pseudocode.

    3. What are various types of C operators?

    4. Write a for loop statement to print numbers from 10 to 1.

    5. Define array.

    6. Name any two library functions used for string handling.

    7. What is the need for functions?

    8. What is the uses of pointers?

    9. Write any two preprocessor directives in C.

    10. Differentiate between structure and union.

    PART B -- (5 16 = 80 Marks)

    11. a) Write in detail about the evolution and the various generations of (16)

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    51

    computers.

    (OR)

    b) Explain the basic computer organisation using a neat diagram. (16)

    12.

    a) Write about the need and types of looping statements in C language

    and discuss with examples.

    (16)

    (OR)

    b) Write about the need and types of branching statements in C

    language and discuss with examples.

    (16)

    13.

    a)

    i) Write a C program to reverse a string. (8)

    ii) Write a C program to print the Fibonacci series of a given

    number.

    (8)

    (OR)

    b) Write a C program to print the sum of two matrices. (16)

    14. a) Explain the following with suitable examples.

    i) Function declaration (8)

    ii) Call by reference, call by value. (8)

    (OR)

    b) i) Explain function with and without arguments with examples

    for each.

    (10)

    ii) What is recursion? Give an example. (6)

    15 a) i) What is storage class? List and explain with example. (8)

    ii) Define and declare a structure to store date, which including

    day, month and year.

    (8)

    (OR)

    b) Write a C program to create a mark sheet for students using

    structure.

    16

    --------

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    52

    Reg. No:

    Question Paper Code : 570147

    B.E./B.Tech. DEGREE EXAMINATIONS, MAY/JUNE 2014

    First Semester

    Civil Engineering

    GE 6151 COMPUTER PROGRAMMING

    (Common to all Branches)

    (Regulation 2013)

    Time : Three hours Maximum: 100 Marks

    Answer ALL questions

    PART A -- (10 2 = 20 Marks) 1. Convert the binary number 110 100 111 101 to octal.

    6475

    2. Draw a flow chart to find biggest of two number.

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    53

    3. List different data types available in C

    Standard: int, float,char, void

    Derived: struct,union, array and pointer 4. Write a C program to find factorial of a given number using iteration.

    5. Write example code to declare two dimensional array.

    int a[10][10];

    In the above declaration, a is a 2-dimensional array of size 1010 and totally

    100 locations are allocated for the array variable.

    6. List any four string handling functions.

    char *strcat(s,ct) concatenates source string ct to end of s

    returns s.

    size_t strlen(cs) Determines the length of a string

    char *strcpy(s,ct) Copy string ct to string s return s. Pad

    with '0' if ct has fewer than n characters

    int strcmp(cs, ct) compare string cs to string ct,

    return ct.

    In the above table, variables s and t are of type char *; cs and ct are of

    type const char *; n is of type size_t; and c is an int converted to

    //Factorial using iteration

    #include

    void main()

    {

    int n,factorial=1;

    do{

    printf("Enter number:");

    scanf("%d",&n);

    }while(n14);

    while(n>0)

    factorial*=n--;

    printf("The factorial of n is:%d\n",factorial);

    }

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    54

    void swap(int *px, int *py) /* interchange *px and *py */

    {

    int temp;

    temp = *px;

    *px = *py;

    *py = temp;

    }

    char.

    7. Define Recursion.

    When a function contains a call to itself, its referred to as a recursive function.

    This scheme in general is known as recursion.

    8. What is the difference between pass by value and pass by reference?

    Let us assume that we want to swap the value of two variables x and y. When

    we define a swap function as,

    void swap(int x, int y) /* WRONG */

    {

    int temp;

    temp = x;

    x = y;

    y = temp;

    }

    The above example shows the call by value which will not serve our purpose of

    exchanging. The way to obtain the desired effect is for the calling program to

    pass pointers to the values to be changed. Since the operator & produces the

    address of a variable, &a is a pointer to a. In swap itself, the parameters are

    declared as pointers, and the operands are accessed indirectly through them.

    Pictorially,

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    55

    9. What is the purpose of Unions in C?

    Th

    10. What is the use of pre-processor directives?

    PART B -- (5 16 = (8)0 Marks)

    11

    .

    a) i) Discuss about Generation of digital computer. (10)

    ii) Draw a flow chart to find factorial of a number. (6)

    (OR)

    b) (i) Explain the basic organisation of a computer. (10)

    (ii) Draw a flow chart to find sum first 100 natural numbers. (6)

    12

    .

    a) (i) Write a program to check whether a given number is prime or

    not.

    (8)

    (ii) Write a C program to find sum of digits of an integer. (8)

    (OR)

  • GE6151 COMPUTER PROGRAMMING

    QUESTION BANK

    56

    b)

    i) Write a C program to fmd roots of a quadratic equation. (8)

    ii) Differentiate entry and exit checked conditional constructs

    with an example.

    (8)

    13

    .

    a)

    i) Explain the concept of pass by reference with suitable

    example.

    (8)

    ii) Write a C program to find factorial of a number using

    recursion.

    (8)

    (OR)

    b) i) Write a C program to swap the content of two variables using

    pointers.

    (8)

    ii) Explain the use of pointers in arrays with suitable example. (8)

    14

    .

    a) Write a C program to arrange the numbers in ascending order. (16)

    (OR)

    b) Write a C program to subtract two matrices and display the

    resultant matrix.

    (8)

    15

    .

    a) Explain the concept of storage classes with suitable example. (16)

    (OR)

    b) Write a C program to store the employee information using

    structure and search a particular employee using Employee

    Number.

    16

    ---------------