4
You visited us
4
times! Enjoying our articles?
Unlock Full Access!
Byju's Answer
Other
Quantitative Aptitude
HCF and LCM
What will be ...
Question
What will be the output of the following code segment:
myList = [1,2,3,4,5,6,7,8,9,10]
for i in range(0,len(myList)):
if i%2 == 0:
print(myList[i])
Open in App
Solution
Here, the elements of the list will be printed which are at index such that index%2==0. The index of the list can be represented as:
Element
1
2
3
4
5
6
7
8
9
10
Index
0
1
2
3
4
5
6
7
8
9
Therefore, the output will be the elements at index 0, 2, 4, 6, 8 i.e.
1
3
5
7
9
Suggest Corrections
5
Similar questions
Q.
What will be the output of the following piece of code when executed?
#include<iostream.h>
voidf(int*iptr)
{
*iptr=1;
}
main()
{
int i=0;
f(&i);
cout<<"The value is"<<i<<ends];
return 0;
}
Q.
What is the output after for loop executes for (i =0; i<10;++i)
Printf("%d", i &1);
Q.
Consider the following two C code segments. Y and X are one and two dimensional arrays of size n and
n
×
n
respectively, where
2
≤
n
≥
10.
Assume that in both code segments, elements of Y are initialized to 0 and each element X[i][j] of array X is initialized to i + j. Further assume that when stored in main memory all elements of X are in same main memory page frame.
Code segment 1 :
//
initialize elements of Y to 0
// initialize elements X [i][j] of X to i+j
for (i =0; i < n; i++)
Y [i] + = X [0] [i];
Code segment 2 :
//
initialize elements of Y to 0
// initialize elements X[i][j] of X to i+j
for (i =0; i < n; i++)
Y [i] + = X [i] [0];
Which of the following statements is/are correct?
S1 :
Final contents of array Y will be same in both code segments.
S2 :
Elements of array X accessed inside the for loop shown in code segment 1 are contiguous in main memory.
S3 :
Elements of array X accessed inside the for loop shown in code segment 2 are contiguous in main memory.
Q.
What is the output of the following 'C' program?
main()
{
int i=2;
printf("%d%d,++i,++i);
}
Q.
Consider the following C code segment.
for (i = 0; i < n; i ++)
{
for (j = 0; j < n; j ++)
{
if (i % 2)
{ x + = (4 * j + 5 * i);
y + = (7 + 4 *j);
}
}
}
which one of the following is false?
View More
Join BYJU'S Learning Program
Grade/Exam
1st Grade
2nd Grade
3rd Grade
4th Grade
5th Grade
6th grade
7th grade
8th Grade
9th Grade
10th Grade
11th Grade
12th Grade
Submit
Related Videos
QUANTITATIVE APTITUDE
Watch in App
Explore more
HCF and LCM
Other Quantitative Aptitude
Join BYJU'S Learning Program
Grade/Exam
1st Grade
2nd Grade
3rd Grade
4th Grade
5th Grade
6th grade
7th grade
8th Grade
9th Grade
10th Grade
11th Grade
12th Grade
Submit
AI Tutor
Textbooks
Question Papers
Install app