0% found this document useful (0 votes)
3 views4 pages

C_TEST_04

The document contains a series of C programming test questions that involve various concepts such as string manipulation, memory management, and function behavior. Each question presents a code snippet and asks for the expected output or result after execution. The questions cover topics like array handling, pointer usage, and function parameters.

Uploaded by

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

C_TEST_04

The document contains a series of C programming test questions that involve various concepts such as string manipulation, memory management, and function behavior. Each question presents a code snippet and asks for the expected output or result after execution. The questions cover topics like array handling, pointer usage, and function parameters.

Uploaded by

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

C TEST – 04

1. char s1[ ] = "Andhra", s2[ ] = "TeluguPradesh";


void find(char* s1, char* s2)
{
if(s1 && s2 &&strlen(s1) > 0){
int index = 0, numChars = strlen(s1);
while(index <numChars){
char temp = s1[index];
s1[index] = s2[index];
s2[index] = temp;
++index;
}
}
}
After calling find(s1,s2); function from main what will be s1[] and s2[]?
a. s1[ ] = "Telugu", s2[ ] = "AndhraPradesh";
b. s1[ ] = "TeluguPradesh", s2[ ] = "Telugu";
c. s1[ ] = "AndhraTelugu", s2[ ] = "Andhra";
d. s1[ ] = "TeluguPradesh", s2[ ] = "Pradesh";
2. void main()
{
int a[100];
a[-1] = 1234;
printf("%d\n", a[0]);
}
Output?

a. 0 b. 1234 c. Garbage d. R.T.E

3. void out(char* s)
{
int len = strlen(s)-1, i = 0;
while (i<len) {
char temp = s[i];
s[i] = s[len];
s[len] = temp;
i++;
len--;
}
}
void main()
{
char a[ ] = "Textbook";
out(a);
printf(a);
}
Output?

a. koobtxeT c. txeTbook
b. txeTkoob d. Textbook

4. void car(int x, char **y)


{
int local = (x * x) - 7;
y += 2;
y[local] = "Rose";
}
void main()
{
char* arr[] = {"1234", "5678", "9ABC", "DEFG", "HIJK", "LMNOP"};
car(3, arr);
printf("%s ", arr[4]);
}
Output?

a. defg b. hijk c. Rose d. crash

5. void main()
{
int a = 100;
printf("%d%d" + 2, a);
}
Output?

a. 102 b. 1002 c. %d d. 100

6. #define FIRST_PART 7
#define LAST_PART 5
#define ALL_PARTS FIRST_PART + LAST_PART
void main()
{
printf("%d\n", ALL_PARTS * ALL_PARTS);
}
Output?

a. 47 b. 144 c. 35 d. 49

7. //sizeof(int) is 4, sizeof(char*) is 4
typedef struct{
int a[10];
}tag;
int size(tag* s1)
{
return sizeof(s1->a)/sizeof(s1->a[0]);
}
void main()
{
tag s1 = {1, 2, -2, -4, 5};
printf("%d\n", size(&s1));
}
Output?

a. 5 b. 10 c. 40 d. 20

8. int add(int i, int j)


{
return i+j;
}
void mySwap(int* i, int* j)
{
int temp = *i;
*i = *j;
*j = temp;
}
void main()
{
int i = 2, j = 3;
printf("%d = ", add(i, j));
mySwap(&i, &j);
printf("%d", add(i, j));
}
Output?
a. 5 = 6
b. 5 = Garbage
c. Garbage = 6
d. 5 = 5
9. void star(char src[ ], char* dest)
{
if (sizeof(src) == sizeof(dest))
printf("The given two arrays are of equal size");
else
printf("The given two arrays are of different size");
}
void main()
{
char src[10] = "123", dest[12] = "1234";
star(src, dest);
}
Output?
a. The given two arrays are of different size
b. The given two arrays are of equal size
c. Segmentation fault or run-time error
d. None of these
10. void fun(char* cPtr)
{
if (!cPtr)
return;
strcpy(cPtr, "Lion");
}
void main()
{
char cPtr[] = "Tiger";
fun(cPtr);
printf("%s", cPtr);
}
Output?

a. Lion
b. Tiger
c. Garbage
d. R

You might also like