Computer Sciences > GATE 2025 SET-1 > C Programming
Consider the following C program:
The value printed by the given C program is ______ (Answer in integer)

Correct : 46

The output of the program is 46.
The function gate() processes the input number 14362 digit by digit from left to right using integer division and modulo operations. It uses a variable turn that flips between 0 and 1 at every step — when turn is 1, the current digit is included in the result; when turn is 0, the digit is skipped.
Since turn starts at 0, the first digit is always skipped. Here"s how the digits of 14362 are processed:
• Digit 1 (position 0): turn = 0 → skipped
• Digit 4 (position 1): turn = 1 → included → newnum = 4
• Digit 3 (position 2): turn = 0 → skipped
• Digit 6 (position 3): turn = 1 → included → newnum = 46
• Digit 2 (position 4): turn = 0 → skipped
So the function collects digits at odd positions (1-indexed: 2nd and 4th) — which are 4 and 6 — and returns 46.

Similar Questions

Consider the following two functions void fun1(int n){     if(n == 0) return;       printf(“%d”, n);     fun2(n-2); &...
#175 MCQ
Consider the C functions foo and bar given below: int foo(int val) {     int x = 0;     while (val > 0)     {     &nbs...
#190 MCQ
What is printed by the following ANSI C program? #include<stdio.h> int main(int argc, char *argv[]) {     int a[3][3][3] =     {{...
#311 MCQ

Related Topics

GATE CS 2025 GATE CS 2025 Set-1 Q63 C Program Output gate(14362) Digit Extraction C Integer Arithmetic C C Programming GATE Output Prediction GATE Turn Variable C While Loop Trace GATE CS C Programming GATE 2025 CS Solved Alternate Digit Extraction

Unique Visitor Count

Total Unique Visitors

Loading......