Aptitude Test On C-programming (Pointers And Strings) Set -c

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Mayurkothawade
M
Mayurkothawade
Community Contributor
Quizzes Created: 2 | Total Attempts: 3,499
| Attempts: 1,134 | Questions: 15
Please wait...
Question 1 / 15
0 %
0/100
Score 0/100
1. What will be the output of the program ?   int main() {     inti=3, *j, k;     j = &i;     printf("%d\n", i**j*i+*j);     return0; }

Explanation

j=&i implies *j=i;
*j=3
i**j=3*3=9
i**j*i=9*3=27
i**j*i+*j=27+3=30

Submit
Please wait...
About This Quiz
C Programming Quizzes & Trivia

This aptitude test focuses on assessing skills in C programming, specifically related to pointers and strings. It includes practical questions on structure access, pointer operations, and string manipulation, essential for learners aiming to enhance their programming expertise.

Personalize your quiz and earn a certificate with your name on it!
2. Are the expression *ptr++ and ++*ptr are same?

Explanation

*ptr++ increments the pointer and not the value,
++*ptr increments the value being pointed by ptr .

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

Explanation

The correct answer is *(*(*(*(a+i)+j)+k)+l). This pointer expression is used to access the array element a[i][j][k][l]. The expression starts with a pointer to a, and then adds the offset i to access the correct element in the first dimension. It then adds the offset j to access the correct element in the second dimension. Similarly, it adds the offsets k and l to access the correct element in the third and fourth dimensions, respectively. Finally, the * operator is used to dereference the pointer and obtain the value of the array element.

Submit
4. If the size of integer is 4bytes, What will be the output of the program?

int main()
{
    int arr[] = {12, 13, 14, 15, 16};
    printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
    return 0;
}

Explanation

The output of the program will be "20, 4, 4".

The sizeof operator is used to determine the size of a variable or data type. In this program, it is used to determine the size of the array "arr", the size of the pointer to the first element of the array "arr", and the size of each element in the array "arr".

Since the array "arr" has 5 elements and each element is of type int (which is 4 bytes in size), the size of the array is 5 * 4 = 20 bytes.

The sizeof(*arr) gives the size of the pointer to the first element of the array, which is 4 bytes in this case.

The sizeof(arr[0]) gives the size of each element in the array, which is also 4 bytes.

Submit
5. If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?

Explanation

The '->' operator is used to access data members of a structure through a pointer variable. This operator is used when we have a pointer to a structure and want to access its data members. It is used in the form of 'pointerVariable->member'.

Submit
6. What will be the output of the program ?

int main()
{
    printf(5+"Good Morning\n");
    return 0;
}

Explanation

printf(5+"Good Morning\n"); It skips the 5 characters and prints the given string.
Hence the output is "Morning"

Submit
7. What will be the output of the program ?   int main() {     void *vp;     char ch=74, *cp="JACK";     int j=65;     vp=&ch;     printf("%c", *(char*)vp);     vp=&j;     printf("%c", *(int*)vp);     vp=cp;     printf("%s", (char*)vp+2);     return 0; }

Explanation

Pointer always store integer value so cp will store the memory address of location where string "jack " is stored.

vp = &ch; Will store address of ch in vp so while we print content in printf it will print asccii value of 74 i.e "J"

vp = &j; It will assign address of j to vp again it will print ascii value of 65 as "A"

vp = cp; In this step cp is pointing to memory locatioon where string jack is stored and we r incrementing it by two so it will point to "C"
from sring "JACK" and since we hava given %S in printf so it will print content from c onward ie "CK"

Submit
8. What will be the output of the program ?
int main()
{
    char *str;
    str = "%s";
    printf(str, "K\n");
    return 0;
}

Explanation

printf(str, "K\n"); is replaced with printf("%s" , "K\n");
(since str = "%s";)

So it will print K.

Submit
9. Which of the following function is used to find the first occurrence of a given string in another string?

Explanation

The function strstr() is used to find the first occurrence of a given string within another string. It searches for the substring in the main string and returns a pointer to the first occurrence of the substring. This function is commonly used in string manipulation and searching algorithms.

Submit
10. What will be the output of the program ?
int main()
{
    char str[] = "India\0\is Best\0";
    printf("%d\n", strlen(str));
    return 0;
}

Explanation

The function strlen returns the number of characters in the given string.
Therefore, strlen(str) becomes strlen("India") contains 5 characters. A string is a collection of characters terminated by '\0'.
The output of the program is "5"

Submit
11. Trace the output. int main() {     char str[] = "basic";     char *s = str;     printf("%s ", s++ +3);     printf("%s",s);     return 0; }

Explanation

printf("%s ", s++ +3); -> ic since (s++ +3) and s++ is post increment but +3 just print string from 'i'. It ll not increment the pointer to 3.
printf("%s",s); here after incrementing (s++) It ll print ''asic''.

Submit
12. What will be the output of the program ?   int main() {     int i;     char a[] = "\0";     if(printf("%s", a))         printf("The string is empty\n");     else         printf("The string is not empty\n");     return 0; }

Explanation

The function printf() returns the number of characters printed on the console.
char a[] = "\0"; The variable a is declared as an array of characters and it initialized with "\0". It denotes that the string is empty.
if(printf("%s", a)) The printf() statement does not print anything, so it returns '0'(zero). Hence the if condition is failed.
In the else part it prints "The string is not empty".

Submit
13. What will be the output of the program ?   int main() {     char p[] = "%d\n";     p[1] = 'c';     printf(p, 65);     return 0; }

Explanation

char p[] = "%d\n"; The variable p is declared as an array of characters and initialized with string "%d".
p[1] = 'c'; Here, we overwrite the second element of array p by 'c'. So array p becomes "%c".
printf(p, 65); becomes printf("%c", 65);
Therefore it prints the ASCII value of 65. The output is 'A'.

Submit
14. What will be the output of the program ?

int main()
{
    char str1[] = "Hello";
    char str2[] = "Hello";
    if(str1 == str2)
        printf("Equal\n");
    else
        printf("Unequal\n");
    return 0;
}

Explanation

if(str1 == str2) here the address of str1 and str2 are compared. The addresses of both variables are not same. Hence the if condition is failed.
At the else part it prints "Unequal".

Submit
15. What will be the output of the program ?   int main() {     inti, a[] = {2, 4, 6, 8, 10};     change(a, 5);     for(i=0; i<=4; i++)         printf("%d, ", a[i]);     return 0; } change(int *b, int n) {     int i;     for(i=0; i<n; i++)         *(b+1) = *(b+i)+5; }

Explanation

*(b+1) = *(b+i)+5;
1. i = 0 => *(b+1) ie 4 is replaced by *(b+0)+5 ie 2+5
2. i = 1 => *(b+1) ie 4 is replaced by *(b+1)+5 ie 4+5
3. i = 2 => *(b+1) ie 4 is replaced by *(b+2)+5 ie 6+5
4. i = 3 => *(b+1) ie 4 is replaced by *(b+3)+5 ie 8+5
5. i = 4 => *(b+1) ie 4 is replaced by *(b+4)+5 ie 10+5

Submit
View My Results

Quiz Review Timeline (Updated): Mar 16, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 16, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 25, 2011
    Quiz Created by
    Mayurkothawade
Cancel
  • All
    All (15)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What will be the output of the program ? ...
Are the expression *ptr++ and ++*ptr are same?
What would be the equivalent pointer expression for referring the...
If the size of integer is 4bytes, What will be the output of the...
If a variable is a pointer to a structure, then which of the following...
What will be the output of the program ?...
What will be the output of the program ? ...
What will be the output of the program ?...
Which of the following function is used to find the first occurrence...
What will be the output of the program ?...
Trace the output....
What will be the output of the program ?...
What will be the output of the program ?...
What will be the output of the program ?...
What will be the output of the program ?...
Alert!

Advertisement