Keyword

Result: 265 questions

What is XML?

Answer:

Extensible Markup Language
Used to structure and describe information

- Tag-based syntax like HTML
- You can make up your own tags

View

Which of the following structures has both computed and stored properties?

Quiz

What output will be produced by the code below?

struct Spaceship {
    var name: String {
        willSet {
            print("I'm called \(newValue)!")
        }
    }
}

var serenity = Spaceship(name: "Serenity")
serenity.name = "TARDIS"

Answer:

Correct answer: "I'm called TARDIS!".

Explanation: The willSet property observer is triggered only when the initial value is changed, and not when the struct is created using memberwise initialization.

View

When this code is executed, what data type does convertedNumber have?

let possibleNumber = "1701"
let convertedNumber = Int(possibleNumber)

Correct answer: Int?.

Explanation: Creating an integer from a string will fail if the string does not contain a valid number. So, this constructor returns Int? to give you either a number (on success) or nil (on failure.)

View

What output will be produced by the code below?

let numbers = Array(1..<10)
print(numbers.count)

Correct answer: 9.

Explanation: This array constructor creates values based on the range from 1 up to (but not including 10). This means it will include the numbers 1, 2, 3, 4, 5, 6, 7, 8, and 9, so the count will be 9.

View

What output will be produced by the code below?

struct Spaceship {
    var name: String

    func setName(_ newName: String) {
        name = newName
    }
}
var enterprise = Spaceship(name: "Enterprise")
enterprise.setName("Enterprise A")
print(enterprise.name)

Correct answer: This code will not compile.

Explanation: The setName() method is attempting to change the name parameter, which is prohibited unless the mutating keyword is used. The correct code should be mutating func setName(_ newName: String).

View

What output will be produced by the code below?

func greet(var name: String) {
    name = name.uppercased()
    print("Greetings, \(name)!")
}

greet("River")

Correct answer: This code will not compile.

Explanation: The greet() method declares its name parameter using the var keyword, which was allowed only in old versions of Swift. From Swift 3.0 onwards this construction is no longer valid, so the compiler will refuse to build this code.

 

View

What output will be produced by the code below?

var first = [1, 2, 3]
var second = ["one", "two", "three"]
var third = Array(zip(first, second))
print(third)

Correct answer: [(1, "one"), (2, "two"), (3, "three")].

Explanation: This code creates a Zip2Sequence struct out of two arrays: one containing 1, 2, 3, and another containing "one", "two", "three". The Zip2Sequence will match each item in the first array with the item at the same index in the second array, giving (1, "one") and so on. This is then converted to an array for easier access.

 

View

What output will be produced by the code below?

let string: String = String(describing: String.self)
print(string)

Correct answer: "String".

Explanation: Among the many constructors for strings is one that lets you pass in a class to have the string set to the name of that class. That is, String(describing: String.self) means "create a string out of the name of the String class." This is equivalent to the NSStringFromClass() function that Objective-C developers often use.

 

View

What output will be produced by the code below?

let (captain, engineer, doctor) = ("Mal", "Kailee", "Simon")
print(engineer)

Correct answer: "Kailee".

Explanation: This code demonstrates tuple destructuring, which is a method of pulling a tuple into multiple individual values in one line of code. In this example, it will create three constants (captainengineer, and doctor), giving them the values "Mal", "Kailee", and "Simon" respectively.

 

View

What output will be produced by the code below?

struct Spaceship {
    fileprivate(set) var name = "Serenity"
}

var serenity = Spaceship()
serenity.name = "Jayne's Chariot"
print(serenity.name)

Correct answer: "Jayne's Chariot".

Explanation: Creating a property using fileprivate(set) means that Swift won't let code from other files modify that property directly. However, Swift playgrounds are compiled into a single file when run, and code that exists in the same file as a fileprivate property can access it directly.

 

View

In which case is it mandatory to provide a destructor in a class?

 

Quiz

What is controller in AngularJS

Answer:

In Angular, a Controller is defined by a JavaScript constructor function that is used to augment the Angular Scope.

When a Controller is attached to the DOM via the ng-controller directive, Angular will instantiate a new Controller object, using the specified Controller's constructor function. A new child scope will be created and made available as an injectable parameter to the Controller's constructor function as $scope.

If the controller has been attached using the controller as syntax then the controller instance will be assigned to a property on the new scope.

View

Which of the following would be the best choice of URL structure (for both search engines and humans)?

Quiz

You decide to add a blog to your ecommerce site. What is the preferred url structure?

Quiz

Implementing structured data may help:

Quiz

Which of the following URL structures is NOT recommended to signal language targeting?

Quiz

What are the advantages of a pointer in the C programming language?

Answer: 

Pointer has the following advantages :-

  1. Using pointers we can allocate memory dynamically to structures (Dynamic memory allocation).
  2. Arrays or strings can be passed to function more efficiently.
  3. Better memory management or our program will run faster.
  4. Pointer helps us to build complex data structures like linked lists, trees etc.
  5. Provides alternate way to access array elements of any dimension.
  6. Used to return more than one value from function.
View

Struct is a _____.

Quiz

non-const static member variables must be defined outside of the class for them to be used

struct test
{
    static int x;
};

int test::x;
Quiz

© 2017 QuizBucket.org