Answer to Question #185302 in C++ for Chathu

Question #185302

Given reasons indicating why following identifiers are invalid,

1)goto

2)Struct

3)true

4)2k


1
Expert's answer
2021-04-26T17:29:54-0400

goto - Blaming it for being encoded becomes unreadable, poorly optimized and bugs may appear.

struct - First, the use of structures beats both performance and memory. Each call is a copy, any array of structures is almost guaranteed to fall into the Large Object Heap, which will once again hit both performance (due to increased GC time) and memory (a fragmented heap is very bad).


class Program

{

  static void Main(string[] args)

  {

    Foo[] f = new[] {new Foo {Field = 5}};




    for (int i = 0; i < f.Length; i++)

    {

      Foo foo = f[i];

      foo.Field = 10;

      Console.WriteLine(foo.Field);

    }




    Console.WriteLine(f[0].Field);

  }

}

struct Foo

{

  public int Field;

}




* This source code was highlighted with Source Code Highlighter.


Second, the use of structures is error prone. For example:



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS