C || 2019 Pre board

2nd Semester

Asian, Balkumari ,Gupteshwor ,HDC ,IMS ,Janapriya ,Morgan ,NCC ,SDC,SPAc
Answer:

  1. What is source code? Why is compilation needed?

ANS.  Computer program written in a high-level language which is converted into object code or machine code by a compiler is called source code.Compilation is needed because  to  translates human-readable source code into computer-executable machine code.

  1. What is the use of shift operators? Explain with examples?

ANS. There are two types of shift operators i.e left and right. A left shift is a logical shift (the bits that are shifted off the end are discarded, including the sign bit) and right-shift operator causes the bit pattern in shift-expression to be shifted to the right by the number of positions specified by additive-expression.
 

  1. Discuss different types of decision making statements in C with example.

ANS. Types of decision making are

  • If -If the expression returns true, then the statement-inside will be executed, otherwise statement-inside is skipped and only the statement-outside is executed.

Example

  • if-else- If the expressionis true, the statement-block1 is executed, else statement-block1 is skipped and statement-block2 is executed.

Example:

Nested if else statements- if expression is false then statement-block3 will be executed, otherwise the execution continues and enters inside the first if to perform the check for the next if block, where if expression 1 is true the statement-block1 is executed otherwise statement-block2 is executed.
Example:

 
4.Differentiate between global and local variables with examples?
ANS. Global variables are declared outside any function, and they can be accessed (used) on any function in the program. Local variables are declared inside a function, and can be used only inside that function.

  1. How does an array form an ordinary variable?

ANS. Array is different from ordinary variable because array holds multiple values,whereas an ordinary variable hold a single value. It is true when the elements of the array are treated as individual entities, and when the variables such as an int. It is not generally right to distinguish between a variable and an array.
6.What is the relationship between an array and a pointer? Explain with suitable example.
ANS. Array and pointers in a way store addresses. Variable name of array stores the starting address of the array. Pointers also holds the address of the particular data.

  1. What are the advantages of dynamic memory allocation over static memory allocation?

ANS. The advantages of dynamic memory allocation over static memory allocation are Preventing the wastage of memory. This is because when we use static memory allocation, a lot of memory is wasted because all the memory allocated cannot be utilised.
8.Define enum data types with example.
ANS. Enumeration (or enum) is a user defined data type in C. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.

9.How is a structure initialized? Explain with a example.
ANS. When we declare a structure then memory won’t be allocated for the structure. i.e only writing below declaration statement will never allocate memory

 
10.What is data file? Why is it necessary in programming?
ANS. A file is a place on the disk(not in memory) where a group of related data is stored is called data file.It is necessary in programming because the data file allow us to store information permanently and to access and alter that information whenever necessary.
GROUP B

  1. Write a program and flowchart to read three side of triangle then find it’s area?

12.WAP to write sum of  first  10 odd numbers?

13.WAP to determine whether number is prime or not using function?

14.WAP to read m and n  from a user and and calculate value of m without library function?

15.WAP to read  line of text and print it  in reverse order?

GROUP-C
WAP to read a number in array and perform following statement using switch

  1. Print largest number of array
  2. Check whether the value of x present in array or not

Count the number is even or odd number in array

 
17.WAP that reads three numbers from keyboard as command line augument and display their sum.

18.WAP to create a structure called employee in which data member are name, age, and  salary. Read values form keyboard and save it in data file called “employee.dat”

 
c


Answer:-

  1. what is operator?
  • Operator are tokens which trigger some computation when applied to variable and other objects in an expression.
  1. What is variable?

 A variable has a value that can change. It  is a memory location that can hold a value of a certain data type.

  1. Define structure.
  • Structure is a user defined data type available in c that allows to combine data items of different kinds. To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than one member.
  1. What is global variable.
  • Global variable is a global scope, meaning that it is visible throughout the program, unless shadowed. They hold their values throughout the lifetime of your program an d they can be accessed inside any of the functions defined for the program. 
  1. Basic difference between float and double variable.

 Float of 32 bits(4 byte) in which 23 bits are used to store mantissa and 8 bits are used for storing exponent and 1 bit is used for sign. It can hold 1 5 to 17 decimal digits.
            Double is of 64 bits(8 byte) in which 52 bits are used to store mantissa and 7  bits are used to store exponent and 1 bits is for sign. It can hold about 15 to 17 decimal digits.

  1. Define type conversion.
  • The conversion of predefined data type into another data types is called type conversion.
  1. What is the different between puts and printf?
  • The different between puts and printf are as follows:
  • Puts is used to display only strings whereas printf is used to display integer, float, character, hexadecimal values as well as strings.
  1. What is the use of union in c?
  • A union is a special data type available in c that allows to store different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time.
  1. Define double pointer.
  • A pointer which points to another pointer is known as double pointer.
  1. Explain modular programming?
  • Modular programming is the process of subdividing a computer program into separate sub- program. A module is a separate software component.

c
Answer:-        
        2.write a function that takes 2 integers as arguments and display sum of those numbers.

3.wap to add number at even position  of integer array of size 50.          

4.WAP to display line of text “BEST OF LUCK” 5times using a function.

5.Wap to convert a lower case alphabet to upper case.

6.Wap to copy content of one array to another array .

8.Wap to print the following pattern using loop.
2
4
8
14
22

c1

 
Answer:-

  1. Define language processor.
  • A language processor is a special type software that has the capacity of translating the source code into machine code. Types are:
  • Compiler
  • Assembler
  • Interpreter
  1. Write steps for executing a C program.
  • Write source codes
  • Preprocessor
  • Compile
  • Link Edit
  • Load
  • Execute
  1. Why is else statement used?
  • An else statement is an alternative statement that is used to execute if the result of a previous test condition evaluates to false. The program control automatically goes to the else statement.
  1. What is the syntax of for loop?
  • Syntax:

for([initialization] ; [condition] ; [increment/decrement])

  1. Is it possible to put default: anywhere in the switch condition?
  • Yes, it is possible to put default anywhere in switch condition.
  1. Write down the output of following program:

  1. What is array?
  • An array is a collection of elements of same data type placed in contiguous (consecutively) memory location and can be accessed individually using index to a unique given name.
  1. Show the differences between iteration and recursion.
Iteration Recursion
It process of executing a statement repeatedly, until some specific condition is met. It is the technique of defining anything in terms of itself.
Any recursive problem can be solved iteratively . No all problem have recursive solution.

 

  1. When will you use structure variable?
  • A structure variable is a variable of a structure type. It is used when collection of different data type need to call in a single name.

10.Define pointer.

  • A pointer is a variable that represents the location (rather than value) of a data item.

Q.NO. 12.Write a menu driven program which performs following tasks:
i. Create a structure named student with member variables: roll no, grade, gender, age.
ii. Define ten structure variable type student and using loop take input for all ten structure variables.
iii. Display names of all male students.
iv. Exit

 13:WAP to display the leap year from 1000 to 3000.

Q.No. 14: WAP to display following pattern:
*
**
***
****
*****

Q.No.15:WAP to display following
1/2, 2/3, 3/4, 4/5,………………, n-1/n.

Q.No.16:WAP to find transpose of a matrix.

 
 

IMS

 Define comments with its types.
Ans. Comments are the set of statements that are used in program for the programmer convinence and effectiveness i.e. comment doesn’t represent itself while executing a program.
There are two types of comments in c programming. They are:-

  1. Single line comment //
  2. Multiline comment /*

 
Differentiate between ‘=’ and ‘= =’.
Ans. ‘=’ is assignment operator i.e. it assigns value to the respected variable i.e. x=10;
‘= =’ is relational operator. It checks whether the variable value is equal to the provided value or not i.e. x = = 10;
What do you mean by function?
Ans. Function are the set of statements which are responsible to perform the specified task in the program. There are two types of function i.e. user defined function (structure) and built-in function (printf, scanf, gets, getch etc.).
Differentiate between symbolic and literal constants.
Ans. Symbolic constant, comes into a picture with preprocessor compilers.
Whereas,
A literal constant is directly typed value into a program i.e. int x = 10;
What is linker?
Ans. A linker is a computer program that takes one or more object files generated by a compiler and combines them into one executable program.
What is the use of #include preprocessor directives?
Ans. #include is responsible to insert a particular header from another file.
What do you mean by syntactic and semantic errors?
Ans. Syntactic errors are that errors occurred when we violate the rules of writing syntax.Sematic errors are those errors which occurs when the statements written in program are not meaningful to the compiler.
Why semicolon is used in c program?
Ans. Semicolon is used in C program to terminate the set of statement and forward it to next line for new statement.
What is the use of continue statement?
Ans. The continue statement works somewhat like break statement. Instead of forcing termination, it forces the next iteration of the loop to take place, skipping any code in between.
What is the use of size of ( ) operator?
Ans. Size of ( ) operator is used to compute the size of operand, i.e. it returns the size of a variable.
Group ”B”
2.a) Write a program to find whether entered number is prime or not.
 

b) Print the following pattern:
9
19  29
39  49  59
69  79  89  99
 

c) WAP to print fabonacci series upto nth term entered by the user.


  1. WAP that will read two numbers and display the following menu and carry out the required actions.

MENU:

  1. Addition
  2. Subtraction
  3. Multiplication
  4. Division
  5. Square
  6. Cube

 
 

 
c.jpg


I.            Write the relationship between array and pointer.
Ans: Arrays and pointers are synonymous in terms of how they use to access memory. But, the important difference between them is that, a pointer variable can take different addresses as value whereas, in case of array it is fixed. In C , name of the array always points to the first element of an array.
II.            Make a distinction between if statement and switch statement.
Ans: In if statement we use if and in switch statement we use switch as main keyword variable. To note a decision from number of choice we use switch statement and if statement tells the compiler that what to follow in a decision control structure.
III.            Can a function return more than one value?
Ans: No, we cant return more than one value at a time using function because calling function holds only one return value from called function at a time.
IV.            Define variable.
Ans: An entity that may change is variable.
V.            Why dynamic memory allocation concept is used in programs?
Ans: Because it allocates free memory at run time. This reserves the memory required by the program.
VI.            How union helps to save memory?
Ans: By it accessed only one member at any given time. Since, same memory is shared by all members one variable can reside into memory at a time.
VII.            What is structure variable?
Ans: A struct in c is a composite data type declaration that defines a physically grouped list of variables under one name in a block of memory, allowing a different variables to accessed via a single pointer or by struct decleared name which returns the same address.
VIII.            What is the use of “\t” in c program?
Ans: \t helps to print the value in horizontal or vertical tab.
IX.            What are the different types of operator used in c programming?

  • Arthematic operator
  • Assignment operator
  • Increment and decrement operator
  • Relational operator
  • Conditional operator

X.            Which character terminates a string?
Ans: \0 (null) terminates a string.
3. WAP to do the following over a list of numbers
a)         Create a structure named student with a member variables : roll, name, grade, gender, age.
b)                        Define ten structure variables of type student and using loop take input for all ten structure variables.
c)          Display names of all male students.
Ans:

6.  WAP to read any two integer number n1 and n2 and develop a function that takes these two numbers as argument and print all the even integer numbers from n1 to n2.

7. WAP to copy string. Also write a program to concatenate two string.

c

  1. Write the step while executing program?

Ans: There  are 3 step to executing program they are:

  1. writing a source code
  2. compiling and linking the code
  3. executing of the program.
  1. What is constant?

Ans: A constant is a quantity that doesn’t change during the execution of the program constant are divided into two types they are: Character onstant and Numeric

  1. What is function of size of operator?

Ans:The sizeof operator can be used to get the size of classes, structures, unions and any other user defined data type.

  1. What is Escap sequence ? list out any three.

Ans:  Escap sequence is a non-printing character used in C. it is the character combinations consisting of a backslash (\) followed by a letter or a combination of digits. They are :  /a , /t ,/n  etc.

  1. What is the use of break statement?

Ans: also used is switch statement which causes a transfer of control out of the entire switch statement , to the  first statement following the switch statement.

  1. What is array? How it can be declared and initialized.

Ans: An array is a group of related data items that  shares a common name it is a data structure that store number of data items as a single entity .  it can be declared as int a[3],  b[4]

  1. What is function?

Ans: A function is a block of statement that perform a particular specific task .

  1. What is argument? where it I used?

Ans:  It is the means for communication between calling and called function It is used in a function are generally local variable for the function.

  1. What is pointer?

Ans: It is special type of variable that contain a memory address instead of values in pointer.

  1. What is structure?

Ans: structure is a collection of variables under a  single name . the variable may be of different type and each has s name which is used to select it form the structure.
Short question
Program to print “welcome” 3 times.

Wap to check given program prime or not.


Write a program to copy of contents string  to another.

Write a program to print array of string.

pre_board_NCC_page-0001


Answer:-

  1. How to open and close a Data file? Explain with syntax.
    • The library function fopen is used to open a data file. It’s syntax is :

ptr_var=fopen (file_name,file_mode)
Where, file_name and file_mode are strings that represent the name of the data file and the manner in which the data file will be utilized.
The file is closed using library function fclose as: fclose(ptr_var).
 

  1. How union is different from structure?
    • All members within union share the same storage area of computer memory. It takes less memory than structure. The memory required to store a union is same as member that occupies largest memory. Only one member union can be accessed at any given time. Union can be declared as:

 

  1. Declare and initialization the pointer variable with example.
  • Pointer should be declared as

Here, p contains address of num or points to num. This is called pointer initialization.

  1. Explain the different types of function calls?
  • Call by Value
  • Call by Reference

 What is recursion and recursive function?
Recursion is method to define something in terms of itself. Recursion is one of the most programing tools. It is a technique for defining a problem in terms of one or more smaller versions of the same problem.
A recursive function is one that calls itself directly or indirectly to solve a smaller version of its task until a final which does not require a self-call.
 

  1. Write down the basic characteristics of Array?
    • All the elements o an array share the same name and they are distinguished from one another with the help of an element or index number.
    • Memory for array elements is allocated at array declaration time rather than program run time.
    • Once the memory is allocated, its size cannot be grown or shrunk at run time.
    • We have to guess expected size of memory in advance.

 What do you mean by control structure? Explain.
The program statements are executed in same order in which they appear in the source program but if we want to alter the flow of normal execution of a program, control statements are used. Programming construct that contains control statements to control the flow of execution in a program is called control structure.
Explain the repetitive statements (loops)?
Repetition is the process of executing a group of statements more than one time as long as some condition remains true. Loops are used when we want to execute a part of program or block of statement several times. So a loop may be defined as a block of statements which are repeatedly executed foe a certain number of times or until a particular condition is satisfied. Its types are:

  • The  for  loop
  • The while loop
  • The do while  loop

 

  1. How conditional operator works?

It is also known as ternary operator. A ternary operator pair”?:” is available in C to construct conditional expressions of the form exp1?exp2:exp3; where exp1,exp2 and exp3 are expressions.
First evaluate exp1, if exp1 is true then execute exp2. If exp1 is false then execute exp3. Note that only one of the expressions (either exp2 or exp3) is executed.
 

  1. What is escape sequence?
    • An escape sequence is a non-printing character used in C. It is a character combination consisting of a backlash (\) followed by a letter or a digit. For example:
      1. \n = Move cursor to the next or New line o the screen
      2. \t = Horizontal Tab
      3. \v = Vertical Tab

 
Q.No.2, Solution.// WAP demonstrating the use of nested if for finding largest among 3 numbers.

 
Q.No.3, Solution// WAP to generate Fibonacci series up to n terms using recursive function

 
Q.No.5, Solution//WAP to find the sum of square of the elements of the diagonal of the square matrix

Q.No.6, Solution /*WAP to find X of the following series for the given values of a and N
X=a-a2/2+a3/3-a4/4…………………. up to N                        */

Q.No.7, Solution

/* WAP to print the following output using for loop
1
2          2
3          3          3
4          4          4          4
5          5          5          5          5          */

Q.No.8, Solution //WAP to demonstrate the use of pointer to structure

c.jpgAnswer:-

  1. What is structure programming?
  • Structure programming is the specific problem solving method to solve the program by dividing the programs in small blocks known as the modular programming
  1. What is format for printf() and scanf() function?
  • printf(“format string”,argument_list);
  • scanf(“format string”,argument_list);
  1. What is the purpose of double data type?
  • Double data type id used to store decimal numbers (numbers with floating point value) with double precision.
  1. What is the problem in printf(/n);
  • printf(\n);
  1. What is array and write its advantages?
  • Array Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data.
  • its advantages are:-

Arrays represent multiple data items of the same type using a single name.
In arrays, the elements can be accessed randomly by using the index number.
Arrays allocate memory in contiguous memory locations for all its elements.

  1. List out five string handling functions?
  • strcat – concatenate two strings.
  • strchr – string scanning operation.
  • strcmp – compare two strings.
  • strcpy – copy a string.
  • strlen – get string length.
  1. Define type conversion?
  • Type conversion or typecasting refers to changing an entity of one datatype into another. There are two types of conversion: implicit and explicit.
  1. What is operator precedence?
  • operator precedence is the hierarchy of the operators in which they are used In C,precedence of arithmetic operators( *, %, /, +, -)
  1. Differentiate structure and union?

  1. What are the modes of file handling?
r Open for reading. If the file does not exist, fopen()returns NULL.
rb Open for reading in binary mode. If the file does not exist, fopen()returns NULL.
w Open for writing. If the file exists, its contents are overwritten.
If the file does not exist, it will be created.
wb Open for writing in binary mode. If the file exists, its contents are overwritten.
If the file does not exist, it will be created.

 
c
 

  1. Write difference between gets and scanf.
  • gets can take input even after space whereas scanf cannot.
  1. Write down the advantage of “a” mode over “w” mode in file handling.
  • “a” mode can write in a file without erasing previous contents whereas “w” mode erases previous content and write in a file from beginning.
  1. Mention the use of “void” keyword?
  • The use of void keyword is:
    • to declare void pointer
    • to declare a parameter less function
  1. Compare array and structure.
  • Array is the collection of homogenous data whereas structure is the collection of heterogeneous data.
  1. Why p++ executes faster than p=p+1?
  • p++ executes faster than p=p+1 because the value of p++ is replaced in same memory location whereas the value of p=p+1 is stored in new memory location.
  1. What is explicit type casting?
  • Explicit type casting means data type doesn’t changes automatically, we have to define data type.
  1. What is the purpose of using strcmpi function?
  • The purpose of using strcmpi function is t compare two string without any case.

 
14  program to input days and display in th format of year-month-days.
 

 
15.

  1. Sentence and count the number of alphabets ,numbers of space ,number of digits and number of words.

c

c1c2c
c1c
cccc