×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang Basics – Aptitude Questions and Answers

Golang Basics – Aptitude Questions and Answers: This section contains aptitude questions and answers on Golang Basics.
Submitted by Nidhi, on February 17, 2022

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

import "fmt"

func main() {
	var val1 = 25
	var val2, _ = fmt.Printf("%d ", val1)
	fmt.Printf("%d", val2)
}
  1. Compilation Error
  2. 25 2
  3. 25 3
  4. None of these

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

import "fmt"

func main() {
	var val1 = 25
	var val2, _ = fmt.Print(val1)
	fmt.Print(val2)
}
  1. Compilation Error
  2. 252
  3. 25 2
  4. 25 3

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

import "fmt"

func main() {
	var val1 = 25
	var val2, _ = fmt.Println(val1)
	fmt.Println(val2)
}
  1. Compilation Error
  2. 252
  3. 25
    2
  4. 25
    3

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

import "fmt"

func main() {
	var val1 = 'A'
	fmt.Println(val1)
}
  1. A
  2. 65
  3. Compilation Error
  4. None of the these

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

import "fmt"

func main() {
	var val1 = 0x400
	fmt.Println(val1)
}
  1. 400
  2. 0x400
  3. Compilation Error
  4. 1024

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

import "fmt"

func main() {
	var val1 = 0b1011
	fmt.Println(val1)
}
  1. 1011
  2. 11
  3. Compilation Error
  4. 0b1011

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

import "fmt"

func main() {
	var val1 = 10*6 + 6
	fmt.Printf("%c", val1)
}
  1. 66
  2. Runtime Error
  3. Compilation Error
  4. B

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

import "fmt"

func main() {
	var val1 = 255
	var val2 = -1
	fmt.Printf("%02X %02X", val1, val2)
}
  1. 255 255
  2. FF FF
  3. FF -1
  4. 255 -1

9) Which is the correct name for a Golang variable?
(1) -var (2) var-1 (3) _var (4) var_1
  1. Only (1)
  2. Only (2)
  3. Both (1) and (2)
  4. Both (3) and (4)

10) Which special character can be used in GOLANG to separate two parts (words) of a variable/identifier name?
  1. - (Hyphen)
  2. _ (Underscore)
  3. $ (Dollar)
  4. # (Hash)

11) What will be the output of the following program?
import "fmt"

func main() {
	var val = 'AB';
	fmt.Printf("%c",val);
}
  1. AB
  2. A
  3. B
  4. Compilation Error

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

import "fmt"

func main() {
	var val char = 'A'
	fmt.Printf("%c", val)
}
  1. A
  2. 65
  3. Compilation Error
  4. None of the above

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

func main() {
    	var val1 int  = 20;
	fmt.Printf("%d",++val1);
}
  1. Compilation Error
  2. 20
  3. 21
  4. None of the above

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

func main() {
    	var val1 int  = (10,20);
	fmt.Printf("%d",val1);
}
  1. Compilation Error
  2. 10
  3. 20
  4. None of the above

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

import "fmt"

func main() {
	var val1,var2 int  = (10,20);	
	fmt.Printf("%d %d",val1, val2);
}
  1. Compilation Error
  2. 10 20
  3. 20 10
  4. None of the above

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

import "fmt"

func main() {
	fmt.Printf("includehelp.com\rHello\n")
}
  1. Compilation Error
  2. includehelp.comHello
  3. Hellodehelp.com
  4. None of the above

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

import "fmt"

func main() {
	fmt.Printf("includehelp.com\b\b\bHello\n")
}
  1. Compilation Error
  2. includehelp.comHello
  3. includehelp.Hello
  4. None of the above

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

import "fmt"

func main() {
	var val int = 0
	val = 5 | 2 | 1
	fmt.Printf("%d", val)
}
  1. Compilation Error
  2. 7
  3. 6
  4. 5

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

import "fmt"

func main() {
    	static var val int  = 0;
    	val = 5 | 2 | 1;    
	fmt.Printf("%d",val);
}
  1. Compilation Error
  2. 7
  3. 6
  4. 5

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

import "fmt"

func main() {
	var val1 int = 0x10
	var val2 int = 010
	fmt.Printf("%d", val1+val2)
}
  1. 20
  2. 26
  3. 24
  4. None of the above

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

import "fmt"

func main() {
	var val1 int = 013
	var val2 int = 010
	fmt.Printf("%d", val1+val2)
}
  1. 19
  2. 23
  3. 22
  4. None of the above

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

import "fmt"

func main() {
    	var val1 int  = 13;
    	var val2 int  = 10;
    
    	;
    	;
    	;
    
	fmt.Printf("%d",val1+val2);
}
  1. 19
  2. 23
  3. 24
  4. None of the above

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

import "fmt"

func main() {
    	var val1 float32  = 13.24f;
    	var val2 float32  = 10.34f;
 
	fmt.Printf("%f",val1+val2);
}
  1. 23.580000
  2. Compilation error
  3. 23.58
  4. None of the above

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

import "fmt"

func main() {
	var val1 float = 13.24
	var val2 float = 10.34

	fmt.Printf("%f", val1+val2)
}
  1. 23.580000
  2. Compilation error
  3. 23.58
  4. None of the above

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

import "fmt"

func main() {
	var val1 float32 = 13.24
	var val2 float32 = 10.34

	fmt.Printf("%f", val1+val2)
}
  1. 23.580000
  2. Compilation error
  3. 23.58:
  4. None of the above

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

import "fmt"

func main() {
	var val1 = 10
	var val2 = 20
	var val3 = 30

	fmt.Printf("%d%d%d")
}
  1. Compilation Error
  2. Garbage Value
  3. No output
  4. None of these

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

import "fmt"

func main() {
	var str = "%shello "
	fmt.Printf(str, str)
}
  1. Garbage value
  2. hello %shello
  3. %shello hello
  4. None of the above

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

import "fmt"

func main() {
	var a = 65
	fmt.Printf("%d %x %o %c", a, a, a, a)
}
  1. 65 41 101 A
  2. 66 41 Garbage A
  3. Compilation Error
  4. None of the above

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

import "fmt"

func main() {
	var str = "Hello"
	fmt.Printf("%d", fmt.Printf("%s", str))
}
  1. Hello5
  2. 5Hello
  3. Compilation Error
  4. None of the above

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

import "fmt"

func main() {
	var str = "Hello"
	var n = 0

	n, _ = fmt.Printf("%s", str)
	for i := 1; i < n; i++ {
		n, _ = fmt.Printf("%s", str)
	}
}
  1. HelloHelloHelloHelloHello
  2. HelloHelloHelloHelloHelloHello
  3. Compilation Error
  4. None of the above

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

import "fmt"

func main() {
	var val = 'A'

	val++
	val++
	fmt.Printf("%c", val)
}
  1. 67
  2. C
  3. Compilation Error
  4. None of the above

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

import "fmt"

func main() {
	var val = 'A'

	val++
	var val1 = val

	val++
	var val2 = val

	val = val1 + val2

	fmt.Printf("%d", val)
}
  1. 132
  2. 134
  3. 133
  4. Compilation Error

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

import "fmt"

func main() {
	var val = 0
	var a = 10
	var b = 2

	val = a + b*a + 10/2*a

	fmt.Printf("%d", val)
}
  1. 1250
  2. 80
  3. 125
  4. Error

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

import "fmt"

func main() {
	var val = 67

	val += 2
	val++

	fmt.Printf("%c", val)
}
  1. 70
  2. Compilation Error
  3. Runtime Error
  4. F

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

import "fmt"

func main() {
	var val = (6 | 8) & (8)

	fmt.Printf("%d", val)
}
  1. 8
  2. Compilation Error
  3. Runtime Error
  4. F


 
 



Comments and Discussions!

Load comments ↻





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