You are on page 1of 6

END TERM SOLUTION

Q1. (a) void exchange(float *x, float *y)


(b) void exchange(float *, float *);
(c) int evaluate( int x, int (*poly)(int a))
(d) int evaluate( int , int (*)(int ));
(e) void zero( long int bigIntegers[ ])
(f) void zero( long int [ ]);
(g) int add1AndSum(int oneTooSmall[ ])
(h) int add1AndSum(int [ ]);

Q2. 58 Bytes
68 Bytes to store in a two-dimensional array.

Q3. No, we can not collect strings from the keyboard in an array of pointers to strings. The
reason is that when we initialize such array pf pointers, then at the time of initialization, the
pointers will start pointing to some garbage location.
Those uninitialized pointers are not actually pointing anywhere. That array is filled
with garbage, which means that all those pointers could be pointing anywhere at all, most
likely to memory that doesn't belong to you and hence that you have not been granted access
to.

Q4. (i) char vowel[ ] = “AEIOU”;


(ii) char *vowel = “AEIOU”;

Q5. 1. False
2. False
3. False
4. False
5. True
6. True
7. False
8. False
9. False
10. False

Q6. #include<stdio.h>
void main()
{
int len=0;
char str[100];
printf("Enter the string\n");
gets(str);
char *s1=str;
while(*s1!='\0')
{
len++;
s1++;
}
printf("The length of the given string is %d",len);
}

Q7. #include<stdio.h>
void main()
{
char str1[100],str2[100];
printf("Enter the string\n");
gets(str1);
char *s1=str1;
char *s2=str2;
while(*s1!='\0')
{
*s2=*s1;
s1++;
s2++;
}
printf("The copied string is %s",str2);
}

Q8. a) Compiler Error


b) Compiler Error
c) No Output
d) 2
e) 1, 2, 3
f) i) Compiler Error
g) i) No Output
h) i = 60, j = 13
Q9. 1. Bitwise AND
2. “Address of” OR “Ampersand” OR “&”
3. Address
4. %s and %c
5. Bitwise XOR
6. Sorting
7. “Indirection” OR “Dereference Operator” OR “*”
8. Name and Type (Data Type)
9. Automatic
10. continue

Q10. a) F9C
b) F9E
c) F9E
d) 35
e) 45
f) F9C
g) 45
h) F9E
i) 47
j) Garbage Value

Q11.
1. 12
2. 14
3. 6
4. 4
5. 9
6. 1
7. 3
8. 5
9. 7
10. 2

Q12.
1. 2
2. 1
3. 16
4. 11
5. 18
6. 1
7. 0
8. 5
9. 2
10. 3
Q13. It will compare 2 strings and return 1 if they are same else return 0.

Q14. A double pointer is a pointer variable that holds the address of another pointer variable.
For Example:
int a = 10;
int *j = &i;
int *k = &j;

Here, double pointer k stores of another pointer variable j.

Q15. American Standard Code for Information Interchange.

Q16. strcat( )

Q17. Local – Garbage Value


Global – zero ( 0 )
Q18.
(i) (84)10 = (1110)4
(ii) (2C9)16 = (713)10
(iii) (101010)2 = (52)8
(iv) (3674)8 = (011110111100)2

Q19.
#include<stdio.h>
void main()
{
int n, i, j, temp, pos;
printf("Enter the size of array\n");
scanf("%d", &n);
int arr[n];
printf("Enter array elements\n");
for(i=0; i<n; i++)
scanf("%d", &arr[i]);
printf("Array before Sorting\n");
for(i=0; i<n; i++)
printf("%d\n", arr[i]);
for(i=0; i<n; i++)
{
pos = i;
for(j=i+1; j<n; j++)
{
if(arr[j] < arr[pos])
pos = j;
}
if(pos != i)
{
temp = arr[i];
arr[i] = arr[pos];
arr[pos] = temp;
}
}
printf("Array after Sorting\n");
for(i=0; i<n; i++)
printf("%d\n", arr[i]);
}
Q20.
#include<stdio.h>
void main()
{
int n, i, temp, pass;
printf("Enter the size of array\n");
scanf("%d", &n);
int arr[n];
printf("Enter array elements\n");
for(i=0; i<n; i++)
scanf("%d", &arr[i]);
printf("Array before Sorting\n");
for(i=0; i<n; i++)
printf("%d\n", arr[i]);
for(pass=1; pass<=n-1; pass++)
{
for(i=0; i<n; i++)
{
if(arr[i] > arr[i+1])
{
temp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = temp;
}
}
}
printf("Array after Sorting\n");
for(i=0; i<n; i++)
printf("%d\n", arr[i]);
}

Q21.
#include<stdio.h>
void main()
{
int x, y;
float z;
printf("Enter x, y and z");
scanf("%d%d%f",&x, &y, &z);
if(x > 0)
{
y = x - 1;
z = 2 * x;
}
else if(y > 0)
z = y;
else
{
z = x;
y = x + 1;
}
z = z + 1;
printf("%d\n%d\n%f", x, y, z);
}

You might also like