# C-star Round-2 Set-1

Approved & Edited by ProProfs Editorial Team
At ProProfs Quizzes, our dedicated in-house team of experts takes pride in their work. With a sharp eye for detail, they meticulously review each quiz. This ensures that every quiz, taken by over 100 million users, meets our standards of accuracy, clarity, and engagement.
| Written by Bavya
B
Bavya
Community Contributor
Quizzes Created: 1 | Total Attempts: 77
Questions: 21 | Attempts: 77  Settings  • 1.

### Assume that an int variable takes 4 bytes and a char variable takes 1 byte

• A.

Number of elements between two pointer are: 5. Number of bytes between two pointers are: 20

• B.

Number of elements between two pointer are: 20. Number of bytes between two pointers are: 20

• C.

Number of elements between two pointer are: 5. Number of bytes between two pointers are: 5

• D.

Compiler Error

A. Number of elements between two pointer are: 5. Number of bytes between two pointers are: 20
Explanation
The correct answer is that the number of elements between two pointers is 5 and the number of bytes between the two pointers is 20. This means that there are 5 elements stored in memory between the two pointers, and each element takes up 4 bytes of memory. Therefore, the total number of bytes between the two pointers is 20.

Rate this question:

• 2.

### What would be the equivalent pointer expression for referring the array element a[i][j][k][l]

• A.

((((a+i)+j)+k)+l)

• B.

*(*(*(*(a+i)+j)+k)+l)

• C.

(((a+i)+j)+k+l)

• D.

((a+i)+j+k+l)

B. *(*(*(*(a+i)+j)+k)+l)
Explanation
The given correct answer, *(*(*(*(a+i)+j)+k)+l), is the equivalent pointer expression for referring to the array element a[i][j][k][l]. The expression breaks down the array access into multiple levels of indirection, starting with *(a+i) to access the i-th element of the array, then adding j to access the j-th element of the resulting array, then adding k to access the k-th element, and finally adding l to access the l-th element. The * operator is used at each level to dereference the pointer and access the value stored at that memory location.

Rate this question:

• 3.

### What will be the value of var for the following C statement?var = strcmp("Hello", "World");

• A.

-1

• B.

0

• C.

1

• D.

Strcmp has void return-type

A. -1
Explanation
The value of var will be -1 because strcmp() is a function in C that compares two strings. It returns an integer value that indicates the relationship between the two strings. If the first string is less than the second string, it returns a negative value. In this case, "Hello" is less than "World", so var is assigned the value -1.

Rate this question:

• 4.

### Which pre-defined function returns a pointer to the last occurence of a character in a string?

• A.

Strchr(s, c);

• B.

Strrchr(s, c);

• C.

Strlchr(s, c);

• D.

Strfchr(s, c);

B. Strrchr(s, c);
Explanation
The strrchr(s, c) function returns a pointer to the last occurrence of the character 'c' in the string 's'. This function starts searching for the character from the end of the string and returns a pointer to that location.

Rate this question:

• 5.

### The following C expression can be substituted for? if (isalpha(c) && isdigit(c))

• A.

if (isalnum(c))

• B.

if (isalphanum(c))

• C.

if (isalphanumeric(c))

• D.

None of the mentioned

D. None of the mentioned
Explanation
The given C expression cannot be substituted for any of the options provided. The expression checks if the character is both an alphabet and a digit, while the options provided either check if the character is alphanumeric or a combination of alphabet and digit. Therefore, none of the mentioned options can be used as a substitute for the given expression.

Rate this question:

• 6.

### Which of the following structure declaration will throw anerror?

• A.

Struct temp{}s; main(){}

• B.

Struct temp{}; struct temp s; main(){}

• C.

Struct temp s; struct temp{}; main(){}

• D.

None of the mentioned

D. None of the mentioned
Explanation
All of the given structure declarations are correct and will not throw an error. Therefore, the correct answer is "None of the mentioned".

Rate this question:

• 7.

### How will you print \n on the screen?

• A.

Printf(“\n”);

• B.

Echo “\\n”;

• C.

Printf(‘\n’);

• D.

Printf (“\\n”)

D. Printf (“\\n”)
Explanation
The correct answer is "printf (“\”)" because this statement uses the printf function to print the string "\" on the screen. The backslash (\) is used to escape the forward slash (/) character, so it is printed as part of the string.

Rate this question:

• 8.

### Assuming, integer is 2 byte, What will be the output of the program?#include<stdio.h>int main(){    printf("%x\n", -1>>1);    return 0;}

• A.

Ffff

• B.

0fff

• C.

0000

• D.

Fff0

A. Ffff
Explanation
The program is using the right shift operator (>>) to shift the bits of -1 by 1 position to the right. Since the integer is assumed to be 2 bytes, -1 in binary is represented as 1111 1111 1111 1111. Shifting the bits to the right by 1 position results in 1111 1111 1111 1110, which is equal to fffe in hexadecimal. However, the program is using the printf function with the format specifier "%x" which prints the value in hexadecimal. Therefore, the output of the program will be ffff.

Rate this question:

• 9.

### What will be the output of the program?#include<stdio.h>#define SQUARE(x) x*xint main(){    float s=10, u=30, t=2, a;    a = 2*(s-u*t)/SQUARE(t);    printf("Result = %f", a);    return 0;}

• A.

Result = -100.00000

• B.

Result = -25.000000

• C.

Result = 0.000000

• D.

Result = 100.000000

A. Result = -100.00000
Explanation
The program calculates the value of 'a' using the formula 2*(s-u*t)/SQUARE(t), where 's' is 10, 'u' is 30, 't' is 2, and SQUARE(x) is a macro that squares the value of 'x'.

Plugging in the given values, the calculation becomes 2*(10-30*2)/2*2, which simplifies to 2*(-50)/4, and further simplifies to -100/4.

Therefore, the value of 'a' is -100.00000, which is the correct answer.

Rate this question:

• 10.

### What will be the output of the program ?#include<stdio.h>#include<string.h>int main(){    char str1 = "Hello", str2 = " World";    printf("%s\n", strcpy(str2, strcat(str1, str2)));    return 0;}

• A.

Hello

• B.

World

• C.

Hello World

• D.

WorldHello

C. Hello World
Explanation
The program will output "Hello World". This is because the strcat function is used to concatenate str1 and str2, resulting in "Hello World". Then, the strcpy function is used to copy the concatenated string into str2. Finally, the printf function is used to print the contents of str2, which is "Hello World".

Rate this question:

• 11.

### What will be the output of the program?#include<stdio.h>int main(){    unsigned int res;    res = (64 >>(2+1-2)) & (~(1<<2));    printf("%d\n", res);    return 0;}

• A.

32

• B.

64

• C.

0

• D.

128

A. 32
Explanation
The program uses bitwise operators to perform operations on the number 64. The expression `(64 >> (2+1-2)) & (~(1 1) & (~4)`.

First, the number 64 is right-shifted by 1, resulting in 32.

Then, the number 4 is converted to its binary representation, which is 100. The bitwise NOT operator (~) is applied to 4, resulting in 011.

Finally, the bitwise AND operator (&) is applied between 32 and 011, resulting in 000.

Therefore, the output of the program is 0.

Rate this question:

• 12.

### What will be the output of the program ?#include<stdio.h>int main(){    union var    {        int a, b;    };    union var v;    v.a=10;    v.b=20;    printf("%d\n", v.a);    return 0;}

• A.

10

• B.

20

• C.

30

• D.

0

B. 20
Explanation
The program defines a union named "var" which has two members, "a" and "b" of type int. In the main function, a variable "v" of type "var" is declared. The values of "a" and "b" in "v" are assigned as 10 and 20 respectively. The printf statement then prints the value of "a" which is 20. Therefore, the output of the program will be 20.

Rate this question:

• 13.

### Which of the following statements are correct about the program?#include<stdio.h>int main(){    unsigned int num;    int i;    scanf("%u", &num);    for(i=0; i<16; i++)    {        printf("%d", (num<<i & 1<<15)?1:0);    }    return 0;

• A.

It prints all even bits from num

• B.

It prints all odd bits from num

• C.

It prints binary equivalent num

• D.

Error

C. It prints binary equivalent num
Explanation
The given program takes an unsigned integer as input and prints its binary equivalent. The for loop iterates 16 times, each time checking if the ith bit of the input number is 1 or 0. If it is 1, it prints 1, otherwise it prints 0. Therefore, the program prints the binary representation of the input number.

Rate this question:

• 14.

### What will be the output of the program assuming that the array begins at location 1002?#include<stdio.h>int main(){    int a = { {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2},                        {2, 1, 4, 7, 6, 7, 8, 9, 0, 0, 0, 0} };    printf("%u, %u, %u, %d\n", a, *a, **a, ***a);    return 0;}

• A.

1002, 2004, 4008, 2

• B.

2004, 4008, 8016, 1

• C.

1002, 1002, 1002, 1

• D.

Error

C. 1002, 1002, 1002, 1
Explanation
The output of the program will be "1002, 1002, 1002, 1". The variable "a" is a 3-dimensional array, and when we print the values, we use the format specifier "%u" for unsigned integer and "%d" for integer.

In the printf statement, "a" represents the address of the first element of the array, which is 1002. "*a" represents the value at that address, which is also 1002. "**a" represents the value at the address of the first element of the first sub-array, which is again 1002. "***a" represents the value at the address of the first element of the first sub-array of the first sub-array, which is 1.

Rate this question:

• 15.

### Find the missing statement ....to get the output - India #include<stdio.h> #include<string.h> int main() { char str[] = "XXXX\0\India\0"; printf("%s\n", str); return 0; }

• A.

India

• B.

\nIndia

• C.

India\n

• D.

\n

A. India
Explanation
The missing statement is "printf("%s", str);" which prints the value of the variable "str" followed by a line break. In this case, the value of "str" is "India" because the string "XXXX" is overwritten by the string "India" using the null character "\0" as a delimiter.

Rate this question:

• 16.

### Find the missing  statement ..in order to get the address of prt #include <stdio.h>    int main()   {       int a=10;       int *ptr,XXXXXX;      ptr=&a;       pptr=&ptr; }

• A.

**pptr

• B.

*pptr

• C.

*ptr

• D.

**ptr

A. **pptr
Explanation
The correct answer is **pptr because it is the missing statement that is required to get the address of prt. In the given code, pptr is declared as a pointer to a pointer and it is assigned the address of ptr using the & operator. By dereferencing **pptr, we can access the value stored in ptr, which is the address of a.

Rate this question:

• 17.

### Find the missing statement in order to get output  4 #include<stdio.h>   int main()   {    char a;    int n=XXXXXX(a,"cbitt");    printf("value of n is %d",n);    return 0;}

• A.

Printf

• B.

Sprintf

• C.

Getchar

• D.

Scanf

B. Sprintf
Explanation
The missing statement in order to get the output 4 is "sprintf". The "sprintf" function is used to store formatted data into a string variable. In this case, it is used to store the value returned by the function "XXXXXX(a, "cbitt")" into the variable "n". The value of "n" is then printed using the "printf" function.

Rate this question:

• 18.

### Find the missing statement in order to swap two number a and b a=XXXXX;    b=a-b;       a=a-b;

• A.

A+b

• B.

A-b

• C.

B-a

• D.

A*b

A. A+b
Explanation
To swap two numbers a and b, we need to assign the value of a to variable b and the value of b to variable a. In the given code, the missing statement is "b=a+b". This statement assigns the sum of a and b to variable b. By doing this, the original value of a is stored in b. Then, the code proceeds to assign the difference of a and b to variable a, which effectively swaps the values of a and b. Therefore, the correct answer is a+b.

Rate this question:

• 19.

### In the following code to find if a number is armstrong number or not..Find the missing statement #include<stdio.h>       #include<conio.h>       main()       {       int n,r,sum=0,temp;     clrscr(); / printf("enter the number=");       scanf("%d",&n);       temp=n;       while(n>0)       {       r=n%10;       sum=sum+(XXXXX);       n=n/10;       }       if(temp==sum)       printf("armstrong  number ");       else       printf("not armstrong number");       getch();  }

• A.

R*r*r

• B.

R*r

• C.

R

• D.

R*r*r*

A. R*r*r
Explanation
In order to find if a number is an Armstrong number or not, we need to calculate the sum of the cubes of its digits. The missing statement in the code should be "r*r*r" which represents the cube of the digit "r". This statement should be added to the line "sum=sum+(XXXXX)" in the code.

Rate this question:

• 20.

### In order to get the same output twice find the missing statement #include <stdio.h>   int x = 0; void main() { int *ptr = &x; printf("%p\n", ptr); XXXX; printf("%p\n ", ptr); }

• A.

X++;

• B.

X+2;

• C.

X+7;

• D.

X-1;

A. X++;
Explanation
The missing statement is "x++;" which increments the value of x by 1. This means that after the missing statement is added, the value of x will be incremented by 1.

Rate this question:

• 21.

### In order to get output 0  Find the missing statement.. include <stdio.h> void main() { int x = 0; int *ptr = &x; printf("%d\n", XXX); }

• A.

*ptr

• B.

Ptr

• C.

&ptr

• D.

**ptr Back to top