Question

In: Computer Science

1. Select the answer that declares a variable named c that is a C character, initialized...

1. Select the answer that declares a variable named c that is a C character, initialized to the value A.

char *c = 'A';

char c = 'A';

char c = "A";

char *c = "A";

2. Fill in the missing code to produce the desired output:

int a = 0;
int b = 1;
int c;
// Missing code goes here
printf("%d", c);

Desired output:

1

-c = a && b;

-c = a || b;

-Answer not given

-c = a || !b;

3. What is the output of the following code segment:

int a = 1;
  int b = 2;
  int c = a + b;
  printf("%d", c);

-2

-3

-0

-1

4. You need to use printf() and scanf(). What line of code should you include in your code?

#include <stdio.h>

include stdio.h

#include "stdio.h"

import <stdio.h>

5. Select the C language built-in floating-point data types.

float, double

char, short, int, long

hex, float, double

float

6. What is the output of the following code:

int a = 1;
  int b = 2;
  if (a < b) {
    printf("A");
    if (b < a) {
      printf("B");
    } else {
      printf("C");
    }
  }

-ABC

-A

-AB

-AC

7. Fill in the missing code to produce the desired output:

for (/*Missing code goes here*/) {
    printf("%d ", i);
  }

Desired output:

0 1 2

-int i = 1; i < 3; i++

-int i = 1; I <= 3; i++

-int i = 0; i < 3; i++

-Answer not listed

8. Suppose the following code tries to open a file that is not present. How do you handle the error condition?

FILE *f = fopen("exam.ext", "w");
if (/*Missing code goes here*/) {
  //Handle error condition here...
}

-f == nil

-f == NULL

-f != NULL

-f != void

Solutions

Expert Solution

Rate my Solution and comment if any doubts

1:
   ->    option 2 is correct answer i.e.., char c = 'A'; because it is character varaiable named c which is
       initialized to character 'A'.
   ->   option 1 is not correct because it is a character pointer
   -> option 3 is not correct because "A" represents a string
   ->   option 4 is not correct because it is a character pointer that points to a string

2:
   ->   option 2 ( 1 ) is correct answer i.e.., 0 || 1 = 1 (False OR True = True)
   ->   option 1 is not correct answer because (False AND True = False)
   ->   option 4 is not correct answer because (False OR Not True ) is (False OR False = False )
   ->   option 3 is not correct as answer is given
3:
   ->   option 2 which is 3 correct as 1 + 2 = 3
   ->    option 1 is not correct as 1 + 2 != 2
   ->    option 3 is not correct as 1 + 2 != 0
   ->    option 4 is not correct as 1 + 2 != 1

4:
   ->    option 1 ( #include <stdio.h>) is correct answer because it is predefined header file .
       option 3 (#include "stdio.h") is also correct but it uses userdefined header file.
   ->    option 2 and 4 are not correct as it is not correct syntax

5:
   ->   option 1 is correct because both float , double are predefined datatypes for float
   ->   Remaining options are not correct as they do not contain both float and double

6:
   ->   option 4 i.e.., AC is corrrect because as a < b (1 < 2) is True so 'A' is printed is first and then
       b < a (2 < 1) is False So it goes to else So 'C' is printed
   ->    option 1 is not correct as ABC cannot be printed at once
   ->   option 2 is not correct as A only cannot be printed
   ->   option 3 is not correct as AB cannot be printed as a<b and b<a cannot be at the same time
7:
   ->   option 3 i.e.., (int i=0 ; i < 3 ; i++) is correct because
       first i=0 .. 0<3 and 0 will be printed and i is incremented by 1then
       i=1 .. 1<3 and 1 will be printed and i is incremented by 1 then
       i=2 .. 2<3 and 2 will be printed and i is incremented by 1 then
       i=3 .. 3<3 is false so loop will break
   ->   option 1 is not correct as it gives output 1,2
   ->   option 2 is not correct as    as 'I' is not declared

8:
   ->   option 2 (f==NULL) is generally correct as f return NULL if there is no file
   but if you opened a file in write mode which is not exist then it automatically create that file
   ->   option 1 is not correct as nil is notdefined
   ->   option 3 is not correct as if file exist then it goes to if
   ->   option 4 is not correct as void is the return type for the function


Related Solutions

Write a class named GasTank containing: An instance variable named amount of type double, initialized to...
Write a class named GasTank containing: An instance variable named amount of type double, initialized to 0. An instance variable named capacity of type double. A constructor that accepts a parameter of type double. The value of the parameter is used to initialize the value of capacity. A method named addGas that accepts a parameter of type double. The value of the amount instance variable is increased by the value of the parameter. However, if the value of amount is...
C Code Please! Declares a constant variable N and sets it to 42. * Declares an...
C Code Please! Declares a constant variable N and sets it to 42. * Declares an array of integers, with N elements, called fibonacci. * Declares an array of double floating-point numbers, with N-1 elements, called ratio. * Fills the fibonacci array with the numbers in the Fibonacci sequence (Wikipedia is your friend if you don't know what this sequence is about but you want to know).    Into the i-th element of the fibonacci array, you need to put...
Given a String variable named sentence that has been initialized, write an expression whose value is...
Given a String variable named sentence that has been initialized, write an expression whose value is the the very last character in the String referred to by sentence. write it in python
Write a program in C++ that declares an array of 100 integers named scores[]. Prompt the...
Write a program in C++ that declares an array of 100 integers named scores[]. Prompt the user for how many scores they want to enter. Then read in the specified number of ints and store them in the array. Then prompt the user for a passing grade. Use a for loop to go trough the array and count how many scores are passing. Print the count of how many passing scores, and also print a double that is the percent...
Visual C# 2017 Write a program named Eggs that declares four variables of type int to...
Visual C# 2017 Write a program named Eggs that declares four variables of type int to hold the number of eggs produced in a month by each of four chickens, and assign a value to each variable. Sum the eggs, then display the total in dozens and eggs. For example, if the total number of eggs was 95, the output would be 95 eggs is 7 dozen and 11 eggs. Note: For final submission ensure that the total number eggs...
C++ 10.15: Character Analysis Write a program that reads the contents of a file named text.txt...
C++ 10.15: Character Analysis Write a program that reads the contents of a file named text.txt and determines the following: The number of uppercase letters in the file The number of lowercase letters in the file The number of digits in the file Prompts And Output Labels. There are no prompts-- nothing is read from standard in, just from the file text.txt. Each of the numbers calculated is displayed on a separate line on standard output, preceded by the following...
Write a C++ program that declares three one-dimensional arrays named miles, gallons and mpg. Each array...
Write a C++ program that declares three one-dimensional arrays named miles, gallons and mpg. Each array should be capable of holding 10 elements. In the miles array, store the numbers 240.5, 300.0 189.6, 310.6, 280.7, 216.9, 199.4, 160.3, 177.4 and 192.3. In the gallons array, store the numbers 10.3, 15,6, 8.7, 14, 16.3, 15.7, 14.9, 10.7 , 8.3 and 8.4. Each element of the mpg array should be calculated as the corresponding element of the miles array divided by the...
Write a C++ code for these 2 questions 1. Create an integer variable named ‘arraySize’ and...
Write a C++ code for these 2 questions 1. Create an integer variable named ‘arraySize’ and initialize the value to 1000. 2.. Open an output file named ‘GroupAssignment2Results.csv’. The first line of this file should be the column headings: ‘Array Size’, ‘Bubble Sort Time’, ‘Selection Sort Time’, ’Insertion Sort Time’, ‘Quick Sort Time’, ‘Merge Sort Time’.
C# Programming using Windows Form 1. Define a variable named isTrue that stores a value of...
C# Programming using Windows Form 1. Define a variable named isTrue that stores a value of whether something is true or false. Set this variable    to the negative. Output this variable to the txtIsTrue textbox. 2. Define a variable named favoriteGame that could store the name of a game. Set this variable's value to your favorite game. Output this variable to the txtFavoriteGame textbox. 3.. Define a variable named pi that can store real numbers. initialize it to a value...
in C programming language char character [100] = "hello"; a string array variable It is given....
in C programming language char character [100] = "hello"; a string array variable It is given. By writing a function called TranslateString, By accessing the pointer address of this given string, returning the string's address (pointer address) by reversing the string Write the function and use it on the main function. Function void will not be written as. Return value pointer address it will be. Sweat operation on the same variable (character) It will be made. Declaration of the function...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT