Reading assignment - auto variables

1 Like

The variable that its type will be determined by initializer or expression.

When the type of the variable is not known and it will be specified at run time.

When the type of variable is not known and when we want to provide some flexibility at run time.

Run time

1 Like
  1. What is an auto variable?
    A variable whose type is deduced automatically from its initalizer

  2. Why is it convenient to use?
    Because you don’t need to know in advance the type of the value that will be recorded in the variable

  3. When should you use it?
    When you need to store values with multiple and unknown types.

  4. When will the type of an auto variable be determined (compile-time or run-time?)
    At run-time

1 Like
  1. An auto variable it’s a variable whose type will be automatically deduced from its initializer.
  2. It makes the code easy to write and comprehend.
  3. When we need to cut down unnecessary typing of complex data types on the left hand.
  4. It will be determined at compile time.
1 Like

1. What is an auto variable?
A variable that automatically sets its type at initialization

2. Why is it convenient to use?
If a function output to a variable is ambiguous. C++ will deduce it

3. When should you use it?
If the type coming out of return statement isn’t clear

4. When will the type of an auto variable be determined (compile-time or run-time?)
I deduce it’s at run time. Otherwise, it wouldn’t make sense.

1 Like
  1. The variables which are declare inside of a block ae known as automatic or local variables. With auto variables we can declare a variable without specifying its type.
    2.It is convenient because it saves time
    3.We should use it when there is a lot of data types
  2. Compile-time
1 Like

https://academy.ivanontech.com/products/eos-programming-101/categories/1672202/posts/5619950

What is an auto variable?
Auto variable is undefined when written allowing various variables to co-exist.

When should you use it?
Auto: should be used

When will the type of an auto variable be determined (compile-time or run-time?)
Auto variable is defined by the initialized data.

When should you use it?

I think you misunderstood the question, when you should use the variable auto?

When will the type of an auto variable be determined (compile-time or run-time?)

Indeed sir, but in which moment will be determined that data? compile-time or run-time?

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

sorry, should be used when it makes the variable more clear.

1 Like

auto variables are determined at run time. Not sure what happened with my answers.

1 Like
  1. What is an auto variable?
    type of the variable will be determined basing on the initializer

  2. Why is it convenient to use?
    when is not yet clear which type will be a variable, for example when set in a function

  3. When should you use it?
    when you want to be flexible with the variable type

  4. When will the type of an auto variable be determined (compile-time or run-time?)
    run time

1 Like
  1. An auto variable is a variable that deduces its own type

  2. It is convenient to use in situations where it may not be immediately obvious what the type is or the type is complex

  3. Use it when assigning a variable from the return of a function where the return type is unknown or overly complex

  4. The type is determined at compile-time

1 Like
  1. An auto variable doesn’t have a literal type assigned to it upon declaration. Instead, it must infer it’s type from an initializer.

  2. This gives a variable the flexibility to accept values of different types an assume an appropriate form based on those values. This simplifies and reduces code redundancy as to otherwise create multiple variables and functions to work with each type unnecessarily inflates the amount of code required to complete the same task.

  3. It should be used to reduce code output and redundancy as stated above. It also can be used to declare functions or lambda expressions that deduce their return type from their return statement.

  4. Because all variables must have a designated type before run-time, an auto variable’s type will get resolved by the end of compile time.

1 Like

1. What is an auto variable?

Deduces the type of a declared variable from its initialization expression. - Microsoft Docs

2. Why is it convenient to use?

It is convenient to use because the developer does not need to worry about defining types of their properties explicitly and can delegate it to the compiler. As a result, coding becomes more efficient. Also, auto will adapt to any changes in a value’s type.

For example, changing an auto return type function’s return value from a string to int will not require changing the return type of the function, considering auto will adapt this at compile time.

3. When should you use it?

It is recommended for most situations unless the programmer requires a particular conversion.

4. When will the type of an auto variable be determined (compile-time or run-time?)

Compile-time

P.S:

I found it difficult to grasp the use of auto from the source linked as part of this lecture. It would have been better if the actual Microsoft Documentation was provided for this as it is better explained there:

https://docs.microsoft.com/en-us/cpp/cpp/auto-cpp?view=msvc-160

1 Like

1.) What is an auto variable?
A.) an automatic variable is a local variable which is allocated and deallocated automatically when program flow enters and leaves the variable’s scope. The scope is the lexical context, particularly the function or block in which a variable is defined. ( dynamic)
2.) Why is it convenient to use?
A.) when you are not entirely sure what the variables value is or might be, Very useful, get out of jail card in my opinion. :stuck_out_tongue_winking_eye:
3.) When should you use it?
A.) auto has new meaning: it allows you to automatically deduce the type of a variable. Why is that ever useful? Let’s consider a basic example: std::list a; // fill in a for (auto it = a.begin(); it != a.end(); ++it) { // Do stuff here } The auto there creates an iterator of type std::list::iterator. (“which is very handy in my opinion and saves time and effort”.) :nerd_face:
4.) When will the type of an auto variable be determined (compile-time or run-time?)

( in Run-time), after user input.

1 Like

Auto Variables.

  1. An auto variable replaces some or all type declaration.

  2. It is convenient to use an auto variable because it makes the variable declaration more concise.

  3. You should use an auto variable when you want to make your code simpler and tidy. For example, where the types get complex and lengthy, using auto variable can save a lot of typing.

  4. The type of an auto variable can be determined during compiler time.

1 Like
  • What is an auto variable?
    An auto variable has its type deduced by the compiler so it does not have to be determined by the user.

  • Why is it convenient to use?
    If the user does not know what the data type of the variable will be.

  • When should you use it?
    When using lambdas, the specific type is not required, declaring variables in a block scope, and for combining values.

  • When will the type of an auto variable be determined (compile-time or run-time?)
    By compile-time.

1 Like
  1. An auto variable is a placeholder type specifier that will automatically be deduced from its initializer
  2. It is convenient because it can be used to shorten data type specifiers that are long or as a placeholder for unknown variables
  3. You should use it when variable is unknown, complex or requires flexibility
  4. The type of auto variable to be used is determined at compile time
1 Like
  1. What is an auto variable?
    It is a type of variable will be deduced by it’s initializer and is a simple way to declare a variable that has a complicated type.

  2. Why is it convenient to use?
    It makes defining complex and templatized data easier and avoids unwanted implicit conversions

  3. When should you use it?
    When defining complex or templatized data.

  4. When will the type of an auto variable be determined (compile-time or run-time?)
    It is dtermined at compile-time

1 Like
  1. An auto variable is a variable who’s type is not explicitly defined, but inheritable from the context.

  2. It’s convenient to use when the type can be clearly observed.

  3. Should be used when the type can be clearly observed, and can change.

  4. Compile time.

1 Like