ADVERTISEMENT
ADVERTISEMENT

Golang Operators – Aptitude Questions and Answers

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

1) Which is not a bitwise operator?
  1. &&
  2. |
  3. <<
  4. &

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

import "fmt"

func main() {
	var X = 10
	var Y = 2
	var Z = 0

	Z = X & Y

	fmt.Printf("%d", Z)
}
  1. 0
  2. 2
  3. 10
  4. 12

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

import "fmt"

func main() {
	var TV = 0x01
	var MOBILE = 0x02

	var item = 0x00
	var temp = 0x00

	item = item | TV
	item = item | MOBILE

	fmt.Printf("I have purchased ...:")
	temp = (item & MOBILE)
	if temp != 0 {
		fmt.Printf(" MOBILE, ")
	}

	temp = (item & TV)
	if temp != 0 {
		fmt.Printf(" TV")
	}
}
  1. I have purchased ...:
  2. I have purchased ...: MOBILE, TV
  3. I have purchased ...: MOBILE,
  4. I have purchased ...: TV

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

import "fmt"

func main() {
	var val = 0x04

	val = val | 0x04

	fmt.Printf("%d,", val)

	val |= 0x01

	fmt.Printf("%d", val)
}
  1. 4,5
  2. 4,4
  3. 4,8
  4. 8,8

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

import "fmt"

func main() {
	var val = 10 ^ 2
	fmt.Printf("val: %d", val)
}
  1. Compilation error
  2. val: 10
  3. val: 2
  4. val: 8

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

import "fmt"

func main() {
    	var val = 0x0f;

	val &= ~0x02;
	fmt.Printf("%d",val);
}
  1. Compilation error
  2. 13
  3. 22
  4. 10

7) Which Bitwise Operator can be used to check whether a number is EVEN or ODD quickly?
  1. &
  2. |
  3. ^
  4. &&

8) Left shift (<<) and Right shift (>>) operators are equivalent to ___ by 2.
  1. Multiplication and Division
  2. Division and Multiplication
  3. Multiplication and Remainder
  4. Remainder and Multiplication

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

import "fmt"

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

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

import "fmt"

func main() {
	var A float32 = 65.12
	var B int = int(A)

	fmt.Printf("%d\n", B)
}
  1. 65.12
  2. 65
  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 A float32  = 65.12;
    var B int      = (int)A;
     
    fmt.Printf("%d\n",B);   
}
  1. 65.12
  2. 65
  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 A float32 = 65.12
	var B float64 = float(A)

	fmt.Printf("%f\n", B)
}
  1. 65.12
  2. 65.120000
  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 num int = int('A' + 2)

	fmt.Printf("%d\n", num)
}
  1. 67
  2. C
  3. Compilation Error
  4. None of the above


 
 

ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.