Vous êtes sur la page 1sur 3

KLE Technological University

School of Electronics and Communication Engineering

C Hackathon 2019

Assignment 2
Instructions:
• Students are suggested to write modular programs (using Functions).
• Use proper coding standards and documentation formats
• Submission Questions to be submitted by all students in a folder named
their USN.

Questions for Practice:

1)What is the Output of following program?

# include <stdio.h>
void fun(int *ptr)
{
*ptr = 30;
}
int main()
{
int y = 20;
fun(&y);
printf("%d", y);

return 0;
}
a) 20 b)30 c)Compiler error d)Runtime error
2) Write a C program using pointers to generate fibonacci series.

3) Write a C program using pointers to swap two numbers without using third variables.

4) Write a C program using pointers to transpose a matrix.

5) struct node
{
int i;
float j;
}
struct node *s[10];
The above C declaration define ‘s’ to be
a) An array each element of which is a pointer to a structure of type node
b) A structure of two fields, each field being a pointer to an array of 10elements.
c) A structure of three fields: an integer, a float and an array of 10 elements
d) An array each element of which is a structure of type node
6) Write a C program using structures to Store Information of a Student Using Structure

7) Write a C program using structures to Add Two Complex Numbers by Passing Structure
to a Function

8) Write a C program using structures to Calculate Difference Between Two Time Periods

9) union test
{
int x;
char arr[8];
int y
KLE Technological University
School of Electronics and Communication Engineering

C Hackathon 2019

};
int main()
{
printf(“%d”,sizeof(union test));
return 0;
}

Predict the output of the above program. Assume that the size of an integer is 4 bytes and
size of character is 1 byte. Also assume that there is no alignment needed.

a) 12 b) 16 c) 8 d) Compiler error

10) Write a C program to read and print an employee's detail using union.

Questions for Submission

1)

#include<stdio.h>
int main()
{
int a;
char *x;
x = (char *) &a;
a = 512;
x[0] = 1;
x[1] = 2;
printf("%d",a);
return 0;
}
Predict the output of the above program.
a) Machine dependent b) 513 c) 258 d) Compiler error

2) Write a C Program Swap Numbers in Cyclic Order Using Call by Reference and pointers

E.g.- Value before swapping:

a=1
b=2
c=3
Value after swapping:
a=3
b=1
c=2
3) Write a C Program to search element in an array Using Pointer and print the index of the
element. If it doesn’t exists print -1
4) Suppose that in a C program snippet, following statements are used.
KLE Technological University
School of Electronics and Communication Engineering

C Hackathon 2019

i) sizeof(int);

ii) sizeof(int*);

iii) sizeof(int**);

Assuming size of pointer is 4 bytes and size of int is 4 bytes, pick the most correct answer
from the given options.

a) Only (i) would compile successfully and it would return size as 4


b) All (i),(ii) and (iii) would compile successfully and would return the same size 4
c) All (i),(ii) and (iii) would compile successfully and size of each would be different
and would be decided at run time
d) (ii) and (iii) would result in compile error but (i) would compile and result in size=4

5) Write a C program to evaluate the size of Structure Without using Sizeof Operator.

6) Write a C program to read and print an employee's detail using structure.

7) Write a C program using structure to read item details used in party and calculate all
expenses, divide expenses in all friends equally.This program will read item name, price,
quantity and number of friends.

8) Write a C program to demonstrate the example of nested structure.

9) Write a C Program to Store Information of marks obtained by a student in 5 subjects


using structures with dynamic memory allocation.

10) Write a C union program to extract individual bytes from an unsigned int

e.g.-

Integer number: 2864434397


hex: AABBCCDD
Individual bytes: AA BB CC DD

Vous aimerez peut-être aussi