Pergunta de entrevista da empresa Zeus Learning Pvt. Ltd

Find the bug in code. int sum; for (int i=1; i<11; ++i) sum=sum+i; printf("%d",sum);

Respostas da entrevista

Sigiloso

23 de set. de 2019

If it C language then i know that you will have to declare all variables prior to any logical code, here 'int i=1'; is not permitted

6

Sigiloso

2 de ago. de 2021

Sum=0 is not given

Sigiloso

24 de dez. de 2022

There are several issues with this code(As per JavaScript): The int data type is not recognized in JavaScript. In JavaScript, you should use let or var to declare variables. The for loop syntax is incorrect. In JavaScript, the syntax for a for loop is for (let i = 0; i < 10; i++). The ++i increment operator is not recognized in JavaScript. In JavaScript, you should use i++ instead. The printf function is not recognized in JavaScript. In JavaScript, you should use console.log() to print output to the console. The correct should be: let sum = 0; for (let i = 1; i < 11; i++) { sum = sum + i; } console.log(sum);

Sigiloso

24 de jul. de 2021

The sum is not initialised hence it will be using the garbage value already present in it

1