Question

C programming 1) When setting a two-dimensional character array, how is the size (number of characters)...

C programming

1)

When setting a two-dimensional character array, how is the size (number of characters) in the second dimension set?

Select an answer:

  • The number of elements are equal to the average size of all the strings.

  • To the length of the longest string; you don't need to add one because the first array element is zero.

  • To the length of the longest string, plus one for the null character.

  • The second dimension is equal to the number of strings, plus one.

2)

Yuri wants to use constant Y in a for loop. Which of the following is valid?

Select an answer:

  • for(y=0;y

  • for(x=1;x

  • for(y=0;y<20;y++)

  • all of these answers

3)

Assume that 1 is TRUE and 0 is FALSE, which of the following logical evaluations is TRUE?

Select an answer:

  • FALSE || FALSE

  • !(TRUE || FALSE)

  • !FALSE

  • TRUE && FALSE

4)

Can you display a single character as a value?

Select an answer:

  • Yes, by changing the printf() function's placeholder from %c to %d.

  • Yes, by using a chtype function that output's the character's ASCII value.

  • No, characters and values are separate data types in C.

  • No, though you can use a chtype function to convert digits 0 to 9 to their numeric counterparts.

5)

Which of the following is true?

Select an answer:

  • All arguments passed to a function must be variables.

  • A function's arguments must all be of the same variable type.

  • Arguments passed to a function are treated as variables within the function.

  • None of these are true.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1) When setting a two-dimensional character array, how is the size (number of characters) in the second dimension set?

Ans: To the length of the longest string, plus one for the null character.

Explanation: In C, there is no explicit string data type. So strings are stored as character arrays and to explicitly define end of the string '\0' character is appended to original char array. so string "Hello" will be stored in char array of size 6 and like "Hello\0".

2)  Yuri wants to use constant Y in a for loop. Which of the following is valid?

Ans: for(x=1;x

Explanation: In C, constants are read only data types. So value of a constant can only be read and can't be updated. Only option in which y was not updated was the above one. Note that constants can be read in for loop but any change in value like reassignment, pre/post increments are not allowed.

3)  Assume that 1 is TRUE and 0 is FALSE, which of the following logical evaluations is TRUE?

Ans:  !FALSE

Explanation: In C, _Bool datatype supports true and false values. For that you have to include <stdbool.h> header. Above expression when evaluated gives true value because "!"

4) Can you display a single character as a value?

Ans: Yes, by changing the printf() function's placeholder from %c to %d.

Explanation: In C, you can use format specifiers %c for character and %d for integer. Character are stored as ASCII values between 0 to 255 range. So if a single character when printed with %c specifier outputs character and when printed with %d specifier outputs its ASCII value. e.g. printf("%c",'a') outputs a and printf("%d",'a') outputs 97, ASCII value of 'a'.

5) Which of the following is true?​​​​​​​

Ans: All arguments passed to a function must be variables.

Explanation: In C, you can only pass variables as parameter to function. Though if you want to pass functions, you can store a pointer to that function and pass it as variable to be used to call other function in that function.

Note: In 5th question option 3 is ambiguous because it is not specified if it call by reference or call by value. So in given scenario above specified statement hold true.

Thank you, Hope that helps!

Add a comment
Know the answer?
Add Answer to:
C programming 1) When setting a two-dimensional character array, how is the size (number of characters)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 8 A C-string is a sequence of characters terminated by the null character. True False...

    Question 8 A C-string is a sequence of characters terminated by the null character. True False D Question 9 What is the longest C-string that can be put into this C-string variable? char s[9]; There is not enough information to determine the 8th Question 10 D AC string variable is just an array of characters without the null character. True False Question 11 5 pts If you have already removed a character in char variable ch) from the input stream,...

  • Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} ...

    Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} consisting of all strings that contain two consecutive c's and end with b.                   Your FSM program should include the following three static methods (Java) or functions (C):                                           a.    int nextState(int state, char symbol)                                  A state-transition function that returns the next state based on the                                  current state and an input symbol. This function should also return                                  -1 when an invalid input character is detected.                                  State...

  • Assignment 1) Your function will only write the Nth character of the array, supplied as a...

    Assignment 1) Your function will only write the Nth character of the array, supplied as a parameter by the caller. This is an example prototype (although you may want to change the return value type, based on the second twist, below). void writeArrayNthBackward(const char [], int, int, int); The first three arguments serve the same purpose as in the iterative example. The fourth argument (an int) supplies the N for the Nth character to print in the array. If n...

  • In C++: You are to write two functions, printString() and testString(), which are called from the...

    In C++: You are to write two functions, printString() and testString(), which are called from the main function. printString (string) prints every character in the string to std::cout with a space after every character and a newline at the end. testString (string) returns true if the string contains characters that are in sorted order, false otherwise. You may assume that all characters are lowercase and only alphabetical characters are present. See the main() to see how the two functions are...

  • Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string"...

    Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string" is a sequence of characters. In the C language anything within double quotes is a "string constant" so you have been seeing strings all semester. But we can also have string variables. In the C language these are implemented as an array of char, e.g. char name (10]: In order to make these variables easier to work with, it has been universally agreed that...

  • C PROGRAMMING Implement a function (using only #include library) that can encrypt/decrypt with a substitution cipher....

    C PROGRAMMING Implement a function (using only #include library) that can encrypt/decrypt with a substitution cipher. cipher_sub (a, b, c, d) a is the string that has the data that will be encrypted or decrypted b is the string that has the result of the encrypt/decrypt c is the code string used for our substitution cipher (27 entries plus '\0' character) d is an integer that will pass two constants defined as ENC (encrypt) or DEC (decrypt) --> The function...

  • Write a program that replace repeated three characters in a string by the character followed by 3...

    Write a program that replace repeated three characters in a string by the character followed by 3. For example, the string aabccccaaabbbbcc would become aabc3ca3b3cc. When there are more than three repeated characters, the first three characters will be replaced by the character followed by 3. You can assume the string has only lowercase letters (a-z). Your program should include the following function: void replace(char *str, char *replaced); Your program should include the following function: void replace(char *str, char *replaced);...

  • Write a C program that takes two sets of characters entered by the user and merge...

    Write a C program that takes two sets of characters entered by the user and merge them character by character. Enter the first set of characters: dfn h ate Enter the second set of characters: eedtecsl Output: defend the castle Your program should include the following function: void merge(char *s3, char *s1, char *s2); The function expects s3 to point to a string containing a string that combines s1 and s2 letter by letter. The first set might be longer...

  • please answer all question CSE 110 Introduction to Computer Science 41. An array of size 10,...

    please answer all question CSE 110 Introduction to Computer Science 41. An array of size 10, has only nine slots for storing values TRUE FALSE 42. When is the external name of the file used in the program? A. Any time you read or write to the file B. Never C. Only when reading from the file D. When opening the file stream 43. Creating a flow chart when designing a complex algorithm is a waste of time. TRUE 44....

  • In C Programming Language In this lab you will implement 4 string functions, two using array...

    In C Programming Language In this lab you will implement 4 string functions, two using array notation and two using pointers. The functions must have the signatures given below. You may not use any C library string functions. The functions are 1. int my strlen (char s ) - This function returns the number of characters in a string. You should use array notation for this function. 2. int my strcpy (char s [], char t I)- This function overwrites...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT