×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang if-else – Aptitude Questions and Answers

Golang if-else – Aptitude Questions and Answers: This section contains aptitude questions and answers on Golang if-else.
Submitted by Nidhi, on February 26, 2022

1) What will be the output of the following program?
package main

import "fmt"

func main() {
	var xyz = 0

	xyz, _ = fmt.Printf("")

	if xyz == 0 {
		fmt.Printf("Okkk")
	} else {
		fmt.Printf("Hiii")
	}
}
  1. Hiii
  2. Okkk
  3. Compilation Error
  4. None

2) What will be the output of the following program?
package main

import "fmt"

func main() {
    var xyz = 0;
    
    xyz,_= fmt.Printf("ABC ");
    
    if( xyz==4)
        fmt.Printf("Okkk");
    else
        fmt.Printf("Hiii");
}
  1. ABC Hiii
  2. ABC Okkk
  3. Compilation Error
  4. None

3) What will be the output of the following program?
package main
import "fmt"

func main() {
    var xyz = 0;
    
    xyz,_= fmt.Printf("ABC ");
    
    if( xyz==4)
    {
        fmt.Printf("Okkk");
    }
    else
    {
        fmt.Printf("Hiii");
    }
}
  1. ABC Hiii
  2. ABC Okkk
  3. Compilation Error
  4. None

4) What will be the output of the following program?
package main

import "fmt"

func main() {
    var xyz = 0;
    
    xyz,_= fmt.Printf("ABC ");
    
    if( xyz==4){
        fmt.Printf("Okkk");
    }
    else{
        fmt.Printf("Hiii");
    }
}
  1. ABC Hiii
  2. ABC Okkk
  3. Compilation Error
  4. None

5) What will be the output of the following program?
package main

import "fmt"

func main() {
    var xyz = 10;
    
    if( xyz=4){
        fmt.Printf("Okkk");
    }else{
        fmt.Printf("Hiii");
    }
}
  1. Hiii
  2. Okkk
  3. Compilation Error
  4. None

6) What will be the output of the following program?
package main

import "fmt"

func main() {
    var xyz = 10;
    
    if(--xyz==10){
        fmt.Printf("Okkk");
    }else{
        fmt.Printf("Hiii");
    }
}
  1. Hiii
  2. Okkk
  3. Compilation Error
  4. None

7) What will be the output of the following program?
package main

import (
	"fmt"
	"unsafe"
)

func main() {
	var X int = 10
	var Y int64 = 20

	if unsafe.Sizeof(X) == unsafe.Sizeof(Y) {
		fmt.Printf("Okkk")
	} else {
		fmt.Printf("Hiii")
	}
}
  1. Hiii
  2. Okkk
  3. Compilation Error
  4. None

8) What will be the output of the following program?
package main

import "fmt"

func main() {
	var X int = 10

	if X == 10 {
		fmt.Printf("Hello...")
		break
		fmt.Printf("Ok")
	} else {
		fmt.Printf("Hiii")
	}
}
  1. Hiii
  2. Hello
  3. Hello Ok
  4. Compilation Error

9) What will be the output of the following program?
package main

import (
	"fmt"
	"unsafe"
)

func main() {
	var X = 10
	var Y int32 = 20

	if unsafe.Sizeof(X) == unsafe.Sizeof(Y) {
		fmt.Printf("Okkk")
	} else {
		fmt.Printf("Hiii")
	}
}
  1. Hiii
  2. Okkk
  3. Compilation Error
  4. None of the above

10) What will be the output of the following program?
package main

import "fmt"

func main() {
	if true {
		fmt.Printf("Okkk")
	} else {
		fmt.Printf("Hiii")
	}
}
  1. Hiii
  2. Okkk
  3. Compilation Error
  4. None of the above

11) What will be the output of the following program?
package main

import "fmt"

func main() {

	var flag = true

	if flag {
		fmt.Printf("Okkk")
	} else {
		fmt.Printf("Hiii")
	}
}
  1. Hiii
  2. Okkk
  3. Compilation Error
  4. None of the above

12) What will be the output of the following program?
package main

import "fmt"

func main() {

	var val = 100

	if val > 20 {
		if val < 20 {
			fmt.Printf("Heyyy")
		} else {
			fmt.Printf("Hiii")
		}
	}
}
  1. Hiii
  2. Heyyy
  3. HiiiHeyyy
  4. Compilation Error

13) What will be the output of the following program?
package main

import "fmt"

func main() {
	var val = 100

	if val == 100 {
		fmt.Printf("ABC ")
	}

	if 100 == val {
		fmt.Printf("XYZ ")
	}
}
  1. ABC
  2. XYZ
  3. ABC XYZ
  4. Compilation Error


 
 



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.