Câu hỏi phỏng vấn Golang
Câu hỏi

What is the difference between C.sleep() and time.Sleep() ?

Câu trả lời

The difference between C.sleep() and time.Sleep() primarily lies in the programming languages and environments they are used in, as well as their parameter specifications.

  1. C.sleep():

    • This function is used in the C programming language.
    • It is typically included through the unistd.h header file on Unix-like systems.
    • The function causes the calling thread to sleep for a specified number of seconds.
    • In C, sleep() takes an argument in seconds. For example, sleep(10); will make the program pause for 10 seconds[1].
  2. time.Sleep():

    • This function is used in the Go programming language, not in C.
    • It is a part of the time package in Go, hence it is called using time.Sleep().
    • The function pauses the current goroutine for the duration specified by the argument.
    • In Go, time.Sleep() takes a duration argument in nanoseconds, unless specified otherwise using time constants. For example, `time.Sle...
middle

middle

Gợi ý câu hỏi phỏng vấn

middle

What is rune type in Go?

expert

When go runtime allocates memory from heap, and when from stack?

middle

Can Go have optional parameters?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào