Professional Documents
Culture Documents
END TERM SOLUTION Cs
END TERM SOLUTION Cs
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.
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);
}
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;
Q16. strcat( )
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);
}