0% found this document useful (0 votes)
40 views43 pages

BCP Solution

This document provides definitions and explanations of various computer programming concepts in C language. It defines an algorithm as a step-by-step process to solve a problem systematically. Variables are named locations used to store changing values. C language features include portability, lack of input/output statements, support for bitwise operators, and modularity. Operators like increment, decrement, relational, and bitwise are also explained.

Uploaded by

bhavanicengpp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views43 pages

BCP Solution

This document provides definitions and explanations of various computer programming concepts in C language. It defines an algorithm as a step-by-step process to solve a problem systematically. Variables are named locations used to store changing values. C language features include portability, lack of input/output statements, support for bitwise operators, and modularity. Operators like increment, decrement, relational, and bitwise are also explained.

Uploaded by

bhavanicengpp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED

N. G. PATEL POLYTECHNIC

GTU SOLUTIONS
COMPUTER ENGINEERING DEAPARTMENT
Subject with Code 4310702 – Basic Computer Programming

(1) What is algorithm?


ALGORITHM
 An algorithm is a finite sequence of well-defined steps or operations for solving
a problem in systematic manner.
 These are rules for solving any problems in proper manner.
 Instructions are written in the natural language.
 It is also called step by step solution.

(2) What is variable? Define rules of defining it.


A variable is a name which is used to store a temporary value. The value of the variable
may change during execution of the program.
Rules for naming variable:
 The variable name may consist of letters (A Z, a z), digits (0 9) and underscore
symbol ( _ ).
Example:
int no_1; / int no1; / int NO1;
 The variable name must begin with a letter. Some system permit underscore
as a first character.
Example:
int 1NO; is not valid
 The length should not be more than eight characters.
 Variable name should not be a keyword.
Example:
int case is not valid
 A white space is not allowed in the name of variable.
Example:

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
int NO 1; is not valid.
 Variable is case sensitive. Uppercase and lowercase are different.
Example: int MAX;int max;
Here both MAX and max are treated as different variable

(3) List the features of ‘C’ language.


FEATURE OF C LANGUAGE
 C is portable.
 C does not support input/output statements.
 C supports bitwise operators.
 C is modular language.
 Speedy execution
 C is stable language.

(4) Evaluate c=++a - b++ where a=6, b=2


a=6, b=2
c = ++a – b++
=7–2
=5

(5) List various bitwise operators.


Bitwise AND ( & )
Bitwise OR ( | )
Bitwise Exclusive OR ( ^ )
Shift left ( << )
Shift right ( >> )

(6) What is program?


 A computer program is a sequence of instructions that can be executed by a
computer to perform a specific task.

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
(7) What is header file? List & explain standard header files in C.
 Header files contain the set of predefined standard library functions that we can
include in our c programs. But to use these various library functions, we have to
include the appropriate header files.
 A header file has a .h extension that contains C function declarations and macro
definition.

(8) Explain goto statement.


THE GOTO STATEMENT
 C supports the goto statements to branch unconditionally from one point to
another in the program.
 The goto requires a label in order to identify the place where the branch is to
be made.
 Label must be followed by colon(:)
 The label is placed immediately before the statement where the control is to
be transferred.

(9) What is Decision statement? List out different decision statements.


 Decision making statements contain conditions that are evaluated by the
program.
 If the condition is true, then a set of statements are executed and if the
condition is false then another set of statements is executed. Otherwise,
statements in the body of else are executed.
 Decision making statement in C language are as follows:
1) if statement
2) switch statement
3) conditional operator statement
4) goto statement

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
(10) Define: (1) Constant (2) keyword (3) Token (any two)
CONSTANT
 Constant means fixed value.
 The value of the constant cannot change during execution of the program.
KEYWORD
 Keywords are those words whose meaning is predefined.
 The programmer cannot change the meaning of keywords.
 There are 32 keywords available in c.
 All the keywords must be written in lowercase.
Token
 The smallest individual unit in a C program is known as C token.
 C has six types of token as given below: Keywords, Identifier, Constants, String
Special Symbols, Operators.

11. List and explain increment and decrement operators.


Increment and Decrement Operators in C
 C has two special unary operators called increment (++) and decrement (--)
operators. These operators increment and decrement value of a variable by 1.
++x is same as x = x + 1 or x += 1
--x is same as x = x - 1 or x -= 1
 Increment and decrement operators can be used only with variables. They can't
be used with constants or expressions.
int x = 1, y = 1;
++x; // valid
++5; // invalid - increment operator operating on a constant value
++(x+y); // invalid - increment operating on an expression
 Increment/Decrement operators are of two types:
1. Prefix increment/decrement operator.
2. Postfix increment/decrement operator.

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
Prefix increment/decrement operator
 The prefix increment/decrement operator immediately increases or decreases the
current value of the variable. This value is then used in the expression. Let's take
an example:
y = ++x;
 Here first, the current value of x is incremented by 1. The new value of x is then
assigned to y. Similarly, in the statement:
y = --x;
 the current value of x is decremented by 1. The new value of x is then assigned to
y.

Postfix Increment/Decrement operator


 The postfix increment/decrement operator causes the current value of the
variable to be used in the expression, then the value is incremented or
decremented. For example:
y = x++;
 Here first, the current value of x is assigned to y then x is incremented.
 Similarly, in the statement:
y = x--;
 the current value of x is assigned to y then x is decremented.
Example
#include <stdio.h>
int main()
{
int a = 10, b = 100;
float c = 10.5, d = 100.5;

printf("++a = %d \n", ++a);


printf("--b = %d \n", --b);
printf("++c = %f \n", ++c);
printf("--d = %f \n", --d);

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC

return 0;
}

12. List and explain relational operators in C.


 Relational operators are used to compare values of two expressions. Relational
operators are binary operators because they require two operands to operate.
 An expression which contains the relational operators is called relational
expression. If the relation is true then the result of the relational expression is 1, if
the relation is false then the result of the relational expression is 0.
 Relational operators are used in decision making and loops.
 The following table lists relational operators along with some examples:
Operator Meaning of Operator Example
== Equal to 5 == 3 is evaluated to 0

> Greater than 5 > 3 is evaluated to 1

< Less than 5 < 3 is evaluated to 0

!= Not equal to 5 != 3 is evaluated to 1

>= Greater than or equal to 5 >= 3 is evaluated to 1

<= Less than or equal to 5 <= 3 is evaluated to 0

Example:
#include <stdio.h>
#include<conio.h>
void main()
{
int a,b;
a=10; b=20;
printf(“Relational Operators output n“);
printf(“a < b is : %d \n“,a<b);
printf(“a <= b is : %d \n“,a<=b);
printf(“a == b is : %d \n“,a==b);

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
printf(“a != b is : %d \n“,a!=b);
printf(“a > b is : %d \n“,a>b);
printf(“a >= b is : %d \n“,a>=b);
getch();
}
Output:
Relational Operators output
a < b is : 1
a <= b is : 1
a == b is : 0
a != b is : 1
a > b is : 0
a >= b is : 0

13. What is compiler? Explain why c is called middle level language.


 Compiler: computer software that translates (compiles) source code written
in a high-level language (e.g., C++) into a set of machine-language instructions
that can be understood by a digital computer's CPU.
 Compilers are very large programs, with error-checking and other abilities.
why c is called middle level language.

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
14. Write down advantages & Disadvantages of ‘C’ programming.

15. Explain Structure of C program in detail. [04]

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC

16. Write a program to print percentage and grade of student. [04]


#include <stdio.h>
#include <conio.h>
void main()
{
int phy, chem, bio, math, comp;
float per;

/* Input marks of five subjects from user */


printf("Enter five subjects marks: ");
scanf("%d%d%d%d%d", &phy, &chem, &bio, &math, &comp);

/* Calculate percentage */
per = (phy + chem + bio + math + comp) / 5.0;
printf("Percentage = %.2f\n", per);

/* Find grade according to the percentage */

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
if(per >= 90)
{
printf("Grade A");
}
else if(per >= 80)
{
printf("Grade B");
}
else if(per >= 70)
{
printf("Grade C");
}
else if(per >= 60)
{
printf("Grade D");
}
else if(per >= 40)
{
printf("Grade E");
}
else
{
printf("Grade F");
}
getch();
}

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
17. What is type conversion? Explain its types in detail. [03]

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC

18. What is Flowchart? Draw various symbol of it. [03]

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
19. Evaluate following expression: (1) 25+2/4 *5/ (6 - 4) [03]
(2) 50 % 2 +3 /3 *4
(1) 25+2/4 *5/ (6 - 4) 25 + 2/4 * 5/2
= 25 + 0.5 * 5/2
= 25 + 2.5/2
= 25 + 1.25
= 26.25
(2) 50 % 2 +3 /3 *4 0+3/3*4
=1*4
=4

20. Explain if ..else ladder with example. [03]

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
21. What is data type? Explain different data types in detail. [03]

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC

22. Write a program to find the largest no from three given no. [03]
#include <stdio.h>
#include<conio.h>
void main() {
int n1, n2, n3;
printf("Enter three numbers: ");
scanf("%d %d %d", &n1, &n2, &n3);
if (n1 >= n2 && n1 >= n3)
printf("%d is the largest number.", n1);

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
// if n2 is greater than both n1 and n3, n2 is the largest
else if (n2 >= n1 && n2 >= n3)
printf("%d is the largest number.", n2);

// if both above conditions are false, n3 is the largest


else
printf("%d is the largest number.", n3);

getch();
}
23. Explain ternary operator. [03]
 Programmers use the ternary operator for decision making in place of longer if and
else conditional statements.
 The ternary operator take three arguments:
1. The first is a comparison argument
2. The second is the result upon a true comparison
3. The third is the result upon a false comparison
 It helps to think of the ternary operator as a shorthand way or writing an if-else
statement. Here’s a simple decision-making example using if and else:
int a = 10, b = 20, c;
if (a < b) {
c = a;
}
else {
c = b;
}
printf("%d", c);
 This example takes more than 10 lines, but that isn’t necessary. You can write the
above program in just 3 lines of code using a ternary operator.

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
 Syntax
condition ? value_if_true : value_if_false
 The statement evaluates to value_if_true if condition is met, and value_if_false
otherwise.
 Here’s the above example rewritten to use the ternary operator:
int a = 10, b = 20, c;
c = (a < b) ? a : b;
printf("%d", c);
 Output of the example above should be:
10
 c is set equal to a, because the condition a < b was true.
 Remember that the arguments value_if_true and value_if_false must be of the same
type, and they must be simple expressions rather than full statements.
24. Explain Storage classes in detail. [03]
1. Storage Classes are used to describe the features of a variable/function.
2. These features basically include the scope, visibility and life-time which help us to
trace the existence of a particular variable during the runtime of a program.
3. C language uses 4 storage classes, namely:
1. auto:
 This is the default storage class for all the variables declared inside a function
or a block. Hence, the keyword auto is rarely used while writing programs in C
language.
 Auto variables can be only accessed within the block/function they have been
declared and not outside them (which defines their scope). Of course, these
can be accessed within nested blocks within the parent block/function in which
the auto variable was declared.
 However, they can be accessed outside their scope as well using the concept
of pointers given here by pointing to the very exact memory location where
the variables reside.
 They are assigned a garbage value by default whenever they are declared.

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
2. extern:
 Extern storage class simply tells us that the variable is defined elsewhere and not
within the same block where it is used.
 Basically, the value is assigned to it in a different block and this can be
overwritten/changed in a different block as well.
 So an extern variable is nothing but a global variable initialized with a legal value
where it is declared in order to be used elsewhere. It can be accessed within any
function/block.
 Also, a normal global variable can be made extern as well by placing the ‘extern’
keyword before its declaration/definition in any function/block.
 This basically signifies that we are not initializing a new variable but instead we are
using/accessing the global variable only.
 The main purpose of using extern variables is that they can be accessed between
two different files which are part of a large program.
3. static:
 This storage class is used to declare static variables which are popularly used while
writing programs in C language.
 Static variables have a property of preserving their value even after they are out
of their scope! Hence, static variables preserve the value of their last use in their
scope.
 So we can say that they are initialized only once and exist till the termination of
the program.
 Thus, no new memory is allocated because they are not re-declared. Their scope
is local to the function to which they were defined.
 Global static variables can be accessed anywhere in the program. By default, they
are assigned the value 0 by the compiler.
4. register:
 This storage class declares register variables which have the same functionality as
that of the auto variables.
 The only difference is that the compiler tries to store these variables in the register
of the microprocessor if a free register is available.

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
 This makes the use of register variables to be much faster than that of the variables
stored in the memory during the runtime of the program. If a free register is not
available, these are then stored in the memory only.
 Usually, few variables which are to be accessed very frequently in a program are
declared with the register keyword which improves the running time of the
program. An important and interesting point to be noted here is that we cannot
obtain the address of a register variable using pointers.
25. Evaluate following condition either TRUE OR FALSE if c=4, c1=3 [02]
1)(c1>c && c !=3) (2) (c1==4 && c==3 || c !=3)
1) (c1>c && c !=3) (3>4 && 4!=3)
= (FALSE && TRUE)
= FALSE
(2) (c1==4 && c==3 || c !=3) (3 == 4 && 4 ==3 || 4!=3)
= (FALSE && FALSE || TRUE)
= ( FALSE || TRUE)
= TRUE
26. Explain switch case with proper example. [04]

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
27. Explain if…else statement with example. [02]

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
28. What is array? Write down the syntax of it.

29. What is 2-d array? Write down the syntax of it.

30. List various operation can be performed on Array.


 Insertion operation
 Deletion operation
 Sorting Operation
 Searching operation
 Merging operation

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
31. List out disadvantage of array.

32. Define following terms i) Actual argument ii) Formal argument.

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
33. Give the difference between library function and user defined function.

User-defined Functions Library Functions


These functions are not predefined in the These functions are predefined in the compiler of
Compiler. C language.
These functions are created by user as per These functions are not created by user as their
their own requirement. own.
User-defined functions are not stored in
Library Functions are stored in special library file.
library file.
In this if the user wants to use a particular library
There is no such kind of requirement to add function, then the user has to add the particular
the particular library. library of that function in header file of the
program.
Execution of the program begins from the Execution of the program does not begin from
user-define function. the library function.

Example: sum(), fact(),…etc. Example: printf(), scanf(), sqrt(),…etc.

34. What is function? Write down advantage of function.

Advantages of Function
 The advantages of using functions are:
 Avoid repetition of codes.
 Increases program readability.
 Divide a complex problem into simpler ones.
 Reduces chances of error.
 Modifying a program becomes easier by using function.

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
35. Explain sscanf() & sprintf() function. (03)
Formatted
Description
functions
The sscanf() function reads the values from a char[] array and store each value
sscanf() into variables of matching data type by specifying the matching format
specifier.

The sprintf() function reads the one or multiple values specified with their
sprintf()
matching format specifiers and store these values in a char[] array.

An example of sscanf() function:


#include<stdio.h>
#include<conio.h>

void main()
{
char ar[20] = "User M 19 1.85";

char str[10];
char ch;
int i;
float f;

sscanf(ar, "%s %c %d", &str, &ch, &i, &f);

printf("The value in string is : %s ", str);


printf("\n");

printf("The value in char is : %c ", ch);


printf("\n");

printf("The value in int is : %d ", i);


printf("\n");

printf("The value in float is : %f ", f);

sscanf(ar, "%s %c %d", &str, &ch, &i);

getch();
}

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
Output
The value in string is : User
The value in char is : M
The value in int is : 19
The value in float is : 1.850000

An example of sprintf() function:


#include<stdio.h>
#include<conio.h>
void main()
{
char target[20];
char name[10] = "Andrea";
char gender = 'F';
int age = 25;
float height = 1.70;

printf("The name is : %s", name);


printf("\n");
printf("The gender is : %c", gender);
printf("\n");
printf("The age is : %d", age);
printf("\n");
printf("The height is : %f", height);

sprintf(target, "%s %c %d %f", name, gender, age, height);

printf("\n");
printf("The value in the target string is : %s ", target);

getch();
}

Output

The name is : Andrea


The gender is : F
The age is : 25
The height is : 1.700000
The value in the target string is : Andrea F 25 1.700000

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
36. Explain character Array with example. (03)
 An array is a collection of same type of elements which are sheltered under a common
name.
 An array is defined as following :
<type-of-array> <name-of-array> [<number of elements in array>];

 Where, type-of-array: It is the type of elements that an array store. If array stores
character elements, then type of array is ‘char’. If array stores integer elements, then
type of array is ‘int’. Besides these native types, if type of elements in array is structure
objects, then type of array becomes the structure.
 name-of-array: This is the name that is given to array. It can be any string but it is
usually suggested that some can of standard should be followed while naming arrays.
At least the name should be in context with what is being stored in the array.
 [number of elements]: This value in subscripts [] indicates the number of elements
the array stores.
// valid
char name[13] = "StudyTonight";
char name[10] = {'c','o','d','e','\0'};

// Illegal
char ch[3] = "hello";
char str[4];
str = "hello";

37. Explain elements of user defined function. (04)


USER DEFINED FUNCTION
1. Function Declaration:
 The Function Declaration is declared behind the header file and above the main function
 Syntax:
Return_type function_name(argument(s));
 For example: void sum(int,int);
 In this example sum is a function which is User Defined Function
 This function has two integer argument x and y and the function type of this function is
no return type which is declared by “Void”.

2. Function Definition:
 The syntax of function definition is :
return_type function_name(argument list)
{
body of the function;
}

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
 The function definition is declared after the program. Here the return type function
name and argument list is same as function declaration. Here the function
definition is divided into two parts:
i. Function header
ii. Function body

3. Function call:
 The function call is declared inside the main function and the syntax of function call
is: function_name(argument list);

 W.A.P to find square of given integer number using UDF.


#include<stdio.h>
#include<conio.h>
int sqrt(int x);
void main()
{
int m,n;
printf (“Enter m=“);
scanf (“%d”,&m);
n=square(m);
printf (“The square is %d”,n);
getch();
}
int square(int x)
{
int p;
p=x*x;
return(p);
}
38. Explain call by reference with example. (04)

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC

39. Write a program to find out smallest number with its position from given array.
(04)
#include <stdio.h>
#include<conio.h>
void main() {
int e, i, sval, position;

printf("\nInput the length of the array: ");


scanf("%d", &e);
int v[e];
printf("\nInput the array elements:\n ");
for(i = 0; i < e; i++) {
scanf("%d", &v[i]);
}
sval = v[0];
position = 0;
for(i = 0; i < e; i++) {
if(sval > v[i]) {
sval = v[i];
position = i;
}
}

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
printf("Smallest Value: %d\n", sval);
printf("Position of the element: %d\n", position);
getch();
}

Output:
Input the length of the array: 5
Input the array elements:
25
35
20
14
45
Smallest Value: 14
Position of the element: 3

40. Write all categories of user defined function and explain anyone with example.
(04)

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC

41. Write a program to perform insert operation on Array. (05)

42. Write a program to perform delete operation on Array. (05)

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC

43. Write a program to perform addition of Two 3X3 matrix. Display the result on your
screen.(04)

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC

44. What is Pointer? Write syntax of declaration and initialization.

45. Define Void Pointer.

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
46. List advantages of pointers.

47. Define Structure.

48. What is Typedef?

49. Write a Program which will copy one array into another using pointer. (03)
#include <stdio.h>
#define MAX_SIZE 100 // Maximum array size

/* Function declaration to print array */


void printArray(int arr[], int size);

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC

int main()
{
int source_arr[MAX_SIZE], dest_arr[MAX_SIZE];
int size, i;

int *source_ptr = source_arr;


int *dest_ptr = dest_arr;

int *end_ptr;

printf("Enter size of array: ");


scanf("%d", &size);
printf("Enter elements in array: ");
for (i = 0; i < size; i++)
{
scanf("%d", (source_ptr + i));
}
end_ptr = &source_arr[size - 1];

printf("\nSource array before copying: ");


printArray(source_arr, size);

printf("\nDestination array before copying: ");


printArray(dest_arr, size);

while(source_ptr <= end_ptr)


{
*dest_ptr = *source_ptr;

// Increment source_ptr and dest_ptr


source_ptr++;
dest_ptr++;
}

/* Print source and destination array after copying */


printf("\n\nSource array after copying: ");
printArray(source_arr, size);

printf("\nDestination array after copying: ");

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
printArray(dest_arr, size);

return 0;
}
void printArray(int *arr, int size)
{
int i;

for (i = 0; i < size; i++)


{
printf("%d, ", *(arr + i));
}
}

50. Explain Enumerated data type with example. (03)

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC

51. Explain Union with suitable example. (03)

52. Explain Array of Pointer with proper example. (04)


Array of pointers
 It is collection of addresses (or) collection of pointers.
 Following is the declaration for array of pointers −
datatype *pointername [size];

For example,
int *p[5];
 It represents an array of pointers that can hold 5 integer element addresses.
 ‘&’ is used for initialisation.
 For Example,

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
int a[3] = {10,20,30};
int *p[3], i;
for (i=0; i<3; i++) (or) for (i=0; i<3,i++)
p[i] = &a[i];
p[i] = a+i;

 Accessing
Indirection operator (*) is used for accessing.
For Example,
for (i=0, i<3; i++)
printf ("%d", *p[i]);

Example program
#include<stdio.h>
main ( ){

int a[3] = {10,20,30};


int *p[3],i;

for (i=0; i<3; i++)


p[i] = &a[i];

printf ("elements of the array are \n");


for (i=0; i<3; i++)
printf ("%d \t", *p[i]);
}

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
53. Explain Pointer to Pointer with Proper example. (05)

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
54. Explain effect of Increment and Decrement operator on pointer. (05)
Increment/Decrement of a Pointer
 Increment: It is a condition that also comes under addition. When a pointer is
incremented, it actually increments by the number equal to the size of the data type for
which it is a pointer.
For Example:
 If an integer pointer that stores address 1000 is incremented, then it will increment by
2(size of an int) and the new address it will points to 1002. While if a float type pointer
is incremented then it will increment by 4(size of a float) and the new address will be
1004.
 Decrement: It is a condition that also comes under subtraction. When a pointer is
decremented, it actually decrements by the number equal to the size of the data type
for which it is a pointer.
For Example:
 If an integer pointer that stores address 1000 is decremented, then it will decrement by
2(size of an int) and the new address it will points to 998. While if a float type pointer is
decremented then it will decrement by 4(size of a float) and the new address will be
996.
 Below is the program to illustrate pointer increment/decrement:
#include <stdio.h>
int main()
{
// Integer variable
int N = 4;

// Pointer to an integer
int *ptr1, *ptr2;

// Pointer stores
// the address of N
ptr1 = &N;
ptr2 = &N;

printf("Pointer ptr1 before Increment: ");


printf("%p \n", ptr1);

// Incrementing pointer ptr1;


ptr1++;

printf("Pointer ptr1 after Increment: ");


printf("%p \n\n", ptr1);

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC

printf("Pointer ptr1 before Decrement: ");


printf("%p \n", ptr1);

// Decrementing pointer ptr1;


ptr1--;

printf("Pointer ptr1 after Decrement: ");


printf("%p \n\n", ptr1);

return 0;
}

55. Write a Program which will create product structure with related member variable and
get one product information from user, store it in structure and display on your computer
screen. (04)

#include <stdio.h>
struct student {
char name[50];
int roll;
float marks;
} s;

int main() {
printf("Enter information:\n");
printf("Enter name: ");
fgets(s.name, sizeof(s.name), stdin);

printf("Enter roll number: ");


scanf("%d", &s.roll);
printf("Enter marks: ");
scanf("%f", &s.marks);

printf("Displaying Information:\n");
printf("Name: ");
printf("%s", s.name);
printf("Roll number: %d\n", s.roll);
printf("Marks: %.1f\n", s.marks);

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.


SARDAR VALLABHBHAI PATEL EDUCATION SOCIETY MANAGED
N. G. PATEL POLYTECHNIC
return 0;
}

Output
Enter information:
Enter name: Jack
Enter roll number: 23
Enter marks: 34.5
Displaying Information:
Name: Jack
Roll number: 23
Marks: 34.5

Prepared By Mr. Ritesh J. Patel Computer Engg. Dept.

You might also like