C Importent Questions of first five units


C Programming and Data Structures Important Questions (First 5 Units)
1.  Explain and specify the interactions between various components that support the basic functionality of a computer?
2.  Discuss in detail the program execution steps?
3 List the basic data types, their sizes and range of values supported by ‘C’ language?
4.  Describe the purpose of commonly used conversion characters in scanf() function?
5.  Explain the only ternary operator available in ‘C’ with illustrative example?
6. Differentiate between call by value and call by reference with suitable examples?
7. Write a ‘C’ program using functions to check whether the given 3x3 matrix is symmetric or not?
8. Explain how strings are declared and initialized in ‘C’?
9.  What are the arithmetic operators that are permitted on pointers?
10. Write a ‘C’ function to reverse the string passed as an argument that cannot be altered?
11.  Briefly explain the type definition statement in ‘C’? Give any two examples where usage of type definition statement increases the readability of programs?
12.  Write a ‘C’ program to read, write, add, subtract, multiply and divide two complex numbers? (Represent complex number using structures).
13. Define Algorithm? What are the characteristics that any algorithm should satisfy?
14 Draw a flowchart for finding maximum of given three integers?
15. Differentiate between compiler and interpreter?
16 Differentiate between if-else-if ladder and switch statement?
17.  What is the implicit type conversion hierarchy that is applied while evaluating expressions?
18.  List and give examples for different bitwise operators available in ‘C’?
19.  What is the need for user-defined functions?
20.  What are the different ways in which 1-dimensional arrays can be declared and initialized?
21 Write a C program using recursion for finding GCD (Greatest Common Divisor) of two given numbers?
22.  Explain the syntax with suitable examples the dynamic memory allocation functions available in C?
23.  Write a C function to find the length of a string passed as an argument?
24. Differentiate between structures and unions?
25. What do you mean by bit fields? How bit fields are different from structures?
26. Suppose or oppose the statement “In C a structure contains a union inside it”.
Give suitable example?
27. Distinguish between getc() and getchar() functions?
28. Differentiate between application software and system software?
29.  Draw a flowchart for finding the sum of ‘n’ numbers starting from 1?
30. Briefly discuss various computing environments with neat diagrams?
31.  What do you mean by operator precedence and associativity? How one can override the precedence defined by C language? Give illustrative examples?
32 Explain the structure of a C program?
33.  Discuss with suitable examples the storage classes available in C?
34 Derive the expression for finding the address of any element of a 1-dimensional array?
35 Discuss briefly the following pointers.
I. Pointer pointing to a variable
II. Pointer pointing to a constant
III. Constant pointer pointing to a variable
IV. Constant pointer pointing to constant.
36. Write a C program to swap two integers using functions.
37. How many possible ways one can access the members of a structure using a structure variable and a pointer to a structure variable? Illustrate with examples.
38 Differentiate between Arrays of structures and structures containing arrays with suitable examples?
39.  List the activities involved in each phase of waterfall system development life cycle model?
40. What are the different types of errors one can encounter during the program execution?
41.  What is an identifier? What are the naming rules for identifiers in C?
42.  List different categories of C operators based on their functionality? Give examples?
43.  Explain different types of coding constants in a C?
44. Explain different categories of functions in C with simple illustrative examples?
45. Write a C program using functions to calculate the factorial of a given number?
46.  Demonstrate command-line arguments using a simple program? Explain?
47. Differentiate between a pointer and a variable? How a pointer is declared and initialized? What do you mean by pointer to another pointer?
48.  Write a C function to convert the string passed as an argument to its uppercase equivalent?
49.  What is an enumerated type? How it can be declared? What are the different ways one can initialize enumerations?
50. Differentiate between self referential and nested structures with suitable examples?

51.  Explain different categories of an algorithm with an example?
52. What are the differences between signed and unsigned data types, list out them?
53.  Explain the types of operators available in C?
54. Write a C program with Exclusive OR operation between the two integers and display the result?
55. What are the formatted and unformatted functions? What are the escape sequences?
56. Define Recursion? Write a C-Program to find the factorial of a number using Recursion? 
57.  Describe the features of pointers? Explain an array of pointer with an example?
58. Write a C program to accept string using character pointer and display it?
59.  Write C-structures for departmental store application. Each departmental store contains departmental store Id (3 characters), store location (string), items (structures) and number of items. A store can offer 1 to 1000 items. Each Item contains Item code (4 characters), current stock, unit of measure in the following set (Single, dozen, kilogram, liter, meter, square meter) and price. Using this structure, Write C- function to count the number of items whose price is above the given amount.

60.  What is meant by compilation? Explain in detail?
61. What are the C keywords? Elaborate them?
62. What are unary operators and their uses? Describe logical operators with their return values?
63. Write a C program to shift inputted data by 2 bits left?
64.  Compare different ways of passing parameters with an example.
65 What are Storage classes? Explain different types of Storage Classes? Compare them?
66 Discuss the different arithmetic operations with pointers? Explain the comparison of two pointers?
67. Write a C program to display all the elements of an array using a pointer?
68.  Write C-structures for the College data. College contains the following fields:
College code (2characters), College Name, year of establishment, number of courses and courses. A College can offer 1 to 50 courses. Each course is associated with course name (String), duration, number of students. The number of students in the college is sum of number of students in all the courses in the college. Write a function
int collegeStrength(struct College *c)
that returns the number of students in the college pointed by c.

69.  Define Algorithm and Flow Chart?
70. A utility company charges its customers based on their monthly utilization in terms of units as follows:
Description charge:
First 100 units Rs.10 per unit
Next 200 units Rs. 9 per unit
Next 200 units Rs.8 per unit
Next units Rs.7 per unit
Write an Algorithm and flowchart that reads monthly units of a customer and output the charge amount.
71 What are various conditional and bitwise operations in ‘C’, explain them with an example?
72 Explain various looping statements in ‘C’ language with example?
73. What are various arithmetic and assignment operators in ‘C’, explain them with an example.
75. What is an array? What are different types of array? Explain with examples?
76. hat is a pointer? Define pointer-pointer concept with the help of an example?
77. Write a program using structures to display following information for each student name, Roll-number, mark1, mark2, mark3, total, average?
78.  a) Define the flow chart? Draw a flow chart for finding roots of a quadratic equation with all cases?
79. What are various conditional and relational operators in ‘C’, explain them with an example.
80.  Explain the control statements in ‘C’ language with an example?
81. Explain various looping statements in ‘C’ language with example?
82.  Explain briefly auto and extern storage classes with examples?
83.  Write short notes on scope of variables?
84.  What is an array? What are different types of array? Explain with examples?
85. Write a ‘C’ program using pointer to perform string comparison?
86.  What is a structure? Give its advantage? Give an example of creating and accessing members of a structure?

C and DS Previous BITS of JNTUH 1st Year




I. Choose the correct alternative:
1. If you don’t initialize a static array, what would be the elements set to?                  [    ]
a) 0           b) an known value            c) 1                             d) the character constant ‘\0’
2. The amount of storage required for holding elements of the array depends on       [    ]
a) size           b) data type                     c) data type & size                d) Runtime requirement
3. How many values a function can return at a time                                                    [    ]
a) 2                     b) any number of values                c) only 1              d) no values 0
4. In which parameter passing mechanism, actual argument values are unchanged?   [    ]
a) By value         b) by value reference     c) by name                  d) by reference
5. The statement : printf (“%d”, size of(“”)); prints                                                     [    ]
a) zero             b) 1                 c) garbage                               d) an error message
6. One structure cannot be a member of                                                                      [     ]
a) some other structure            b) an array                   c) a union                    d) the same structure
7. The type of any pointer is :                                                                                      [     ]
a) integer data type      b) character data type c) unsigned integer data type   d) none of these
8. Which of the following is wrong with respect to functions                                      [      ]
a) it facilitates the top-down modular programming  b) function will provide reusability of the code
c) a function will always return some value               d)reduce the length of the program
9. Structure is a data type whose members are                                                                          [     ]
a) all different data types                     b) all same data types
c) may be different or same                  d) no element is defined
10. s[2][1] is same as                                                                                                   [     ]
a) *((s+2)+1)                b) *((s+2)*1)              c) *(*s+2)+1)               d) (*(s+2)+1)

II Fill in the blanks
11. _________is the standard library function is used to reverse the given string
12. The parameters in a function definition are called as ____________ parameters
13. ______________ input/output function is used for reading a string having multiple words
14. The pointer stores ____________of a variable
15. If one or more members are pointer to the same structure, the structure is known as ________
Structure
16. The array elements always stored in ___________memory locations
17. The ___________function is used to allocate block of memory
18. ______________is collection o f dissimilar data items
19. ____________is programming technique that allows the programmer to express operations in terms of themselves
20. _____________is a collection is related information that is permanently stored on the disk.




I. Choose the correct alternative
1. struct a                                                                                                                     [    ]
{
int I;
float j;
};
Which of the following syntax is correct to declare a structure variable
A. struct union a;                     B. union struct a;                     C. union a t;                 D. struct a t;
2. Which of the following is used with printf ( ) function for printing the Address of a variable [    ]
A. %d                                      B. %u                                      C. %f                           D. %c
3. struct{ int I;                                                                                                              [      ]
flaot j;} s; sizeof (s) will be
A. 4 bytes                                B. 2 bytes                                C. 6 bytes                    D. 0 bytes
4. The process of calling a function using pointers to pass the address of variables is known as [    ]
A. call by argument                 B. call by parameter                C. call by value            D. call by reference
5. main( )                                                                                                                     [    ]
{
int a=5,b,*c;c=&a;b=*c;
printf("\n value of a=%d & b=%d",a,b,)}
A. a=3,b=3                               B. a=4,b=4                  C. a=6,b=6                  D. a=5,b=5
6. main( )                                                                                                                     [     ]
{
char *str1="abcd";
char str2[ ]="abcd";
printf ("%d%d%d", sizeof(str1),sizeof(str2),sizeof("abcd"));
}
A. 2 5 5                                   B. 5 5 2                       C. Compiler error                                 D. 5 2 5
7. A block of memory is allocated using the function [ ]
A. falloc( ) B. dalloc( ) C. malloc( ) D. calloc( )
8. In union all members use                                                                             [     ]
A. no location                          B. same location                      C. different location    D. no stroage
9. Which of the following storage classes is used to allocate memory in cpu registers [    ]
A. auto                         B. register                   C. static                        D. extern
10. If we declare an array like int a[4] = {1, 2, 3, 4, 5} then                            [     ]
A. results in compilation error             B. valid but skip the last value 5.
C. valid but skip the first value 1          D. Initializes all values of array with 0
II Fill in the blanks
11. The standard library function strcmp (“JNTUH”, “JNTUK”) retruns ____________
12. The general format of realloc function is ___________
13. Structure elements can be accessed through a pointer to a structure using the operator ____________
14. Self referential structure means __________________
15. A program obtaining its memory while it is running is called as ___________.
16. The name of the array refers to ___________ address
17. In command line arguments program the first argument of the main function Indicates _________
18. In enum wd={SUN, MON, TUE=5, WED, THU, FRI, SAT}, The value Assigned to enum constant FRI is __________
19. Pointers ________ the execution speed (increased/decrease)
20. Pre Processing statements are started with ________ symbol

Storage Classes IN C


Storage Classes
'Storage' refers to the scope of a variable and memory allocated by compiler to store that variable. Scope of a variable is the boundary within which a variable can be used. Storage class defines the scope and lifetime of a variable.
Storage class tells us:
1) Where the variable is stored.
2) Initial value of the variable.
3) Scope of the variable. Scope specifies the part of the program which a variable is accessed.
4) Life of the variable.
A storage class defines the scope (visibility) and life time of variables and/or functions within a C Program.
Every variable and function in C has two attributes: type and storage class.
Types of Storage Classes:
Storage classes are categorized in 4 (four) types as,
·      Static Storage Class

Automatic variables:
                  These are the variables that are declared without using any storage class specification or by susing a storage calss specification ‘auto’. The scope of such variables  are limited to the block of the function in which they are declared. Once the exexcution of the block, or function is complete, these variables are disposed off. auto is the default storage classs for local variables.

Declaration synatax:
      auto type-variables list;
                  Or
      Type variable list;
Example:
            auto int a,b,c;
            auto float x,y;
            int x,y,z;
            float  a,b,c;

Features of Automatic Variables:
·         Storage Space : main memory,
·         Default Initial value: garbage,
·         Scope: : Limited to a block or function in which they are declarted,
·         Life : it remains till the completion of execution of the block or function where they are defined.

Example 1:
main()
{
auto int i=10;
printf(“%d”, i);
}
Output:
10
Example 2:
main()
{
auto int i;
printf(“%d”, i);
}
Output:
1002
In example 1, i value is initialized to 10.So, output is 10.
In example 2, i value is not initialized. So, compiler reads i value is a garbage value.

o    Keyword : static
o    Storage Location : Main memory
o    Initial Value: Zero and can be initialize once only.
o    Life : depends on function calls and the whole application or program.
o    Scope: Local to the block.

Static is the default storage class for global variables. The two variables below (count and road) both have a static storage class.
    static int Count;
        int Road;
        {
            printf("%d\n", Road);
        }
Static variables can be 'seen' within all functions in this source file. At link time, the static variables defined here will not be seen by the object modules that are brought in.
Static can also be defined within a function. If this is done the variable is initialized at run time but is not reinitialized when the function is called. This inside a function static variable retains its value during various calls.
Example:
void func(void);
  
   static count=10; /* Global variable - static is the default */
      main()
   {
     while (count--)
     {
         func();
     }
    }
  
   void func( void )
   {
     static i = 5;
     i++;
     printf("i is %d and count is %d\n", i, count);
   }
    
 This will produce following result
 
   i is 6 and count is 9
   i is 7 and count is 8
   i is 8 and count is 7
   i is 9 and count is 6
   i is 10 and count is 5
   i is 11 and count is 4
   i is 12 and count is 3
   i is 13 and count is 2
   i is 14 and count is 1
   i is 15 and count is 0

NOTE: Here keyword void means function does not return anything and it does not take any parameter. We can memorize void as nothing. Static variables are initialized to 0 automatically.

Example :
main()
{
add();
add();
}
add()
{
static int i=10;
printf(“\n%d”,i);
i+=1;
}
Output:
10
11

Extern is used to give a reference of a global variable that is visible to ALL the program files. When we use 'extern' the variable cannot be initialized as all it does is point the variable name at a storage location that has been previously defined.
When we have multiple files and we define a global variable or function which will be used in other files also, then extern will be used in another file to give reference of defined variable or function. Just for understanding extern is used to declare a global variable or function in another file.

Register Storage class

o    Keyword : register
o    Storage Location : CPU Register
o    Initial Value : Garbage
o    Life : Local to the block in which variable is declared.
o    Scope : Local to the block.
#include <stdio.h>
#include <conio.h>
extern int i=10;
void main()
{
               int i=20;
               void show(void);
               clrscr();
               printf("\n\t %d",i);
               show();
               getch();
}
void show(void)
{
               printf("\n\n\t %d",i);
}

OUTPUT:

20
10

Register Storage Class:

o    Keyword : register
o    Storage Location : CPU Register
o    Initial Value : Garbage
o    Life : Local to the block in which variable is declared.
o    Scope : Local to the block.
Register is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the register size (usually one word) and can’t have the unary '&' operator applied to it (as it does not have a memory location).
               {
            register int  Miles;
               }
Register should only be used for variables that require quick access - such as counters. It should also be noted that defining 'register' goes not mean that the variable will be stored in a register. It means that it MIGHT be stored in a register - depending on hardware and implementation restrictions

Followers