4, 5, 6,

Cards (92)

  • An array is a fixed-size, sequenced collection of elements of the same data type.
  • An array is a sequence of data items that are of the same type, that are indexible, and that are stored contiguously.
  • Arrays are data type that is used to represent a large number of homogenous values.
  • The advantages of the array would be limited if we didn’t also have programming constructs that would allow us to process the data more conveniently.
  • Fortunately, there is a powerful set of programming constructs – loops- that makes array processing easy.
  • syntax of array: []
    ex: Number[0]
  • Following the convention, Number1 becomes Number[1] and Number19 becomes Number[19]. This is known as indexing. Using reference, we now refer to our array using the
    variable i ;
    Number[i];
  • Declaration and Definition of an Array
    An array must be declared and defined before it can be used. Declaration and definition tell the compiler the name of the array, the type of each element, and the size or number of elements in the array. The size of the array is a constant and must have a value at compilation time.
  • What is the primary purpose of loops in programming?
    Performing repetitive actions
  • Which C statement provides a mechanism for repeating a specific set of statements as long as a given condition is true? while
  • What is the syntax of the while statement in C?
    while(expr) {statement; next statement;}
  • How does the while loop work in C? Repeats the statement until expr is zero
  • What is the danger of using a while loop without a proper exit condition? It could lead to an infinite loop
  • In the for loop, what does the condition determine? The number of iterations
  • Which part of the for loop is responsible for setting the loop control variable? Initialization
  • What is the syntax of the for loop in C?
    for(initialization; condition; increment) {statement;}
  • In the for loop, when is the condition evaluated? At the beginning of the loop
  • Which variation of the for loop allows using multiple variables to control the loop?
    Nested for loop or Comma-separated variables
  • What is the purpose of a nested for loop? Repeating a set of statements
  • What is the syntax for a nested for loop in C?
    for(initialization1; condition1; increment1) {for(initialization2; condition2; increment2) {statement;}}
  • What is the syntax of the do statement in C?
    do {statement;} while(expr); next statement;
  • How does the do loop work in C? execute and evaluate if while is true, it repeats, if not it move on.
  • When is the condition in the do loop evaluated? At the end of the loop
  • What is the potential risk of an infinite loop in C? It could lead to an endless repetition
  • In the example; while(number != 0) { scanf("%d",&number); sum += number; } printf("the sum of all numbers is %d",sum); what is the purpose of the while loop?
    Read numbers until zero is entered
  • In the example for(x=100;x!=65;x+=5) { z=sqrt(x); printf("The square root of %d is %f",x,z); } how many times will the loop iterate?
    Until x is equal to 65
  • What is the importance of the comma operator in the for loop variation for(x=0,y=0; x+y < 10; x++) { scanf("%d", &y); sum = x + y; } printf("The sum of x and y is %d", sum); ?
    Initializes multiple variables
  • In the context of a for loop, when is the condition evaluated? At the start or end of the loop
  • Why is it essential to have a proper exit condition in loops? Avoids infinite loops
  • In the do loop, when does the evaluation of the expression (expr) take place? ) Before the loop begins
  • What does the statement do { scanf("%d",&num); sum += num; } while (num > 100); printf("The sum is %d", sum); accomplish

    a.) Calculates the sum of numbers greater than 100 b.) Reads numbers until zero is entered c.) Prints the sum of all number d.) Repeats until the sum exceeds 100
  • What is an array in programming? A fixed-size, sequenced collection of elements of the same data type.
  • How are individual elements in an array accessed in C? Using an index.
  • What is the purpose of loops in array processing? To read and write elements in an array conveniently.
  • How is the address of an individual element in an array calculated in C? element address = array address + (sizeof(element) *
  • How can you fill an array with values read from the keyboard? Using a for loop.
  • Can you assign one array directly to another in C? No.
  • If you want to copy the elements of one array to another, what is the correct approach in C?
    for(i=0; i<size; i++) second[i] = first[i];
  • How can you assign values to an array following a specific pattern in C? 

    for(i=0; i<size; i++) array[i] = i * 2;
  • What happens if the number of values provided in array initialization is less than the number of elements in the array?
    The unassigned elements are filled with zeros.