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
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...
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...
Using C# Create a class named Inches To Feet. Its Main()method holds an integer variable named...
Using C# Create a class named Inches To Feet. Its Main()method holds an integer variable named inches to which you will assign a value. Create a method to which you pass inches. The method displays inches in feet and inches. For example, 67 inches is 5 feet 7 inches.
Create a class using C# named InchesToFeet. Its Main()method holds an integer variable named inches to...
Create a class using C# named InchesToFeet. Its Main()method holds an integer variable named inches to which you will assign a value. Create a method to which you pass inches. The method uses 2 ref parameters: feet, inches left of type int and a parameter that is not ref of type int to which you pass inchesinches. For example, 67 inches is 5 feet 7 inches.
Select the most accurate ranking of metallic character among the elements. Group of answer choices Rb...
Select the most accurate ranking of metallic character among the elements. Group of answer choices Rb > Mo = Re > Te > Pb Fr > Fe > Zr > Sb > Ne Ne < Sb < Fe < Zr < Fr Ca < Ba < Fr < K < Li
Write a program in C that declares the following array: int. array[] = { 1, 2,...
Write a program in C that declares the following array: int. array[] = { 1, 2, 4, 8, 16, 32 } Then write some code that accepts a number between 0 and 5 from the user and stores it in a variable called "index". Write some code that retrieves the item specified by the index, like this: int item = array[index]; Then write code that outputs the corresponding array entry based on the number the user entered. Example output: The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT