C Programming Quiz

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Complete the following for loop to print numbers from 1 to 5. for(int i = ___ ; i <= 5; i++){ printf("%d", i); }

1

What is the output of the following code snippet? int count = 5; do { printf("%d ", --count); } while(count > 3);

4 3

#include <stdio.h> int addOne(int x){ return x + 1; } int main() { int x = 5; printf("%d ", x); printf("%d ", addOne(x)); printf("%d ", x); return 0; } What will be the output of the code?

5 6 5

Complete the following array initialization to declare an array named weights with five elements of type double, initializing the first two elements to 55.5 and 60.2 respectively. double weights[5] = { _______ , ________, 0, 0, 0};

55.5, 60.2

What will be the output of the following code snippet? int a = 5, b = 5; if(a > b) printf("A"); else if(a == b) printf("AB"); else printf("B");

AB

User-defined functions are always declare after they are called. Is the statement true or false?

False

Given the following code snippet, what will be the output if the value of x is 4? switch(x) { case 1: printf("One"); break; case 2: printf("Two"); break; case 3: printf("Three"); break; default: printf("Invalid"); }

Invalid

Why is it important to use `fclose` ?

It frees up memory for program It makes sure that file is saved correctly.

What will be the output of the following code snippet? int num = 5; if(num%2 == 0){ printf("%s", "Even"); } else{ printf("%s", "Odd"); }

Odd

#include<stdio.h> int main() { printf("This is ");printf("First Statement.\n");printf("This is Another One."); return 0;}

This is First Statement. This is Another One.

Which of the following statements is true about variables in C?

Variables are containers for storing data values, like numbers and characters. Global variables can be accessed by any function in the program.

Which fopen() mode opens a file for writing at the end of the file, creating the file if it does not already exist?

a

#include<stdio.h> int main() { char a = 'a';int b = 5; printf("%X %Y", b, a); return 0;} What should be the value of Y in the program, so that it will work correctly?

c

A value assigned with _____ keyword cannot be changed again.

const

#include<stdio.h> int main() { char a = 'a';int b = 5; printf("%X %Y", b, a); return 0;} What should be the value of X in the program, so that it will work correctly?

d

How do you access the third element in an array named days?

days[2]

Which data types can be used to represent floating point numbers.

double

Which of the following loops will execute its body 10 times?

for(int i = 0; i < 10; i++) {} for(int i = 1, i <= 10; i++) {}

A combined declaration and assignment of a variable is called ___________.

initialization

Which function is always executed first when the program starts?

main()

Which of the following correctly accesses the member `age `of a structure variable `person`?

person.age

What mode is used to open file when we want to write to the file?

w


Ensembles d'études connexes

DOG Week 34, 21, and 20 Vocab Mexico Minerals, Central America, and The West Indies

View Set