Skip to content
Related Articles

Related Articles

Improve Article

GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 62

  • Last Updated : 26 Dec, 2019

Consider the following C program:




#include <stdio.h>
#include <string.h>
  
void geek1(char *s1, char *s2) {
    char *temp;
    temp = s1;
    s1 = s2;
    s2 = temp;
}
void geek2(char **s1, char **s2) {
    char *temp;
    temp = *s1;
    *s1 = *s2;
    *s2 = temp;
}
int main() {
    char *str1 = "for geek", *str2 = "by geek";
    geek1(str1, str2);
    printf("%s %s", str1, str2);
    geek2(&str1, &str2);
    printf(" %d", (int) strlen(str1));
    return 0;
}

Last printf will printed _______________ .
(A) 2
(B) 7
(C) 3
(D) None of these


Answer: (B)

Explanation: First function geek1 will not swap strings, so first print is for geek by geek.
Now, function geek2 will swap string, and strlen(str1) will return lenght of string “by geek”, which is 7.

Option (B) is correct.

Quiz of this Question

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :