TRENDING NEWS

POPULAR NEWS

What Is Null String In C Definition

C++ String and C string question?

What exactly is a C++ string because isnt a C string an array of characters and null? Are C++ strings string literals defined in the namespace? Also, for atoi it converts a C string to an integer but why can that integer be compared with the C++ strings? How are C++ strings associated with integers?

Write an appropriate array definition for each of the following problem situations.?

I hope this is helpful!

Let's assume you are talking C or C++:
// This would be your solution in C
#include

int main()
{
int c[12] = {1, 4, 7, 10, 13, 17, 20, 23, 27, 31, 34, 37};
char point[] = "NORTH";
return 0;
}

// This would be your solution in C++
#include
using namespace std; // not used(needed) at that point
int main()
{
int c[12] = {1, 4, 7, 10, 13, 17, 20, 23, 27, 31, 34, 37};
char point[] = "NORTH";
return 0;
}

C++: How to check a string for equality with NULL?

Are you checking if a STRING is null?

Try

if (StringName == "")
fixtheeconomy();
else
BegintheZombieApocalypse;

Or are you checking if a character or c-string is null?

Checking individual characters is easy


if (CStringName == '')
fixtheeconomy();
else
BegintheZombieApocalypse;

I'm not entirely sure what the actual character class offers, but you could always check online for a method if you are talking about a character string...Guess if they don't have a method then you could always write one to itterate though it.

How do you initialize char* to an empty string in C?

An empty string in C - meaning one that would be a legal-formed string that would be regarded as a string of zero-length by the string.h string functions and other functions that operate on strings - is simply "". It is an array of char with a element, and the value of that element is (char) 0 or '\0';Confusingly, this character in the ASCII and UTF-8 character sets is also called NUL, which is different from the C NULL used for pointers.So, you could initialize a char pointer to the empty string by thischar *str = "";
Or if you want it to be dynamically allocated using malloc(), you could usechar *str = strdup("");
If you do this, don’t forget to free() it when you’re done with it…Assigning our str to NULL is a Very Different Thing. NULL is not a valid string and attempting to use NULL with the native string functions may cause a crash or (at best) an error return.As for the size of char * being unknown, the thing that’s unknown (in general) is the size of the char pointer itself ( sizeof(char *) ) - meaning the size of space needed to hold the memory address is platform-dependent - but the size of the string being pointed at is known and well-defined on all platforms as being an array of size 1 containing a single value that is one byte long.Yes, “1 byte” can itself be different sizes on different platforms, but it’s at least 8 bits as per the modern C standard, and on modern, non-esoteric hardware (such as GPUs), it will be exactly 8 bits.

What is the difference between 0 and null terminator in a C string?

There's three types of "zeros" involved here:A literal 0 or (char) 0.The standard value of C/C++ NULL, used as a standard value for a "pointer to nothing".  Null pointerThe ASCII value NUL (note no second "L") that is the standard name for ASCII 0.  ASCII character table.  Confusingly, it's pronounced the same way as NULL.  If you want to indicate it as a value, you can use the character literal '\0' in C or C++.A few points:A literal or integer 0 is always safe to use as a terminator for a C string.The ASCII value NUL is not a standard part of the C language definition (and you won't find NUL as a #define in any standard header file), but is part of the ASCII (and Unicode/UTF8) definition.  However, it's always 0, or '\0'.The value NULL is *not* generally safe to use as a terminator for a C string or as an "end of string" test.  It is usually 0, but is typically a ((void *) 0) as it's intended for use with pointers, not scalar values (and if you compile with all warnings enabled, using it with individual elements of a C string will result in a compiler warning).  Note also that the C standard is somewhat coy with the definition of NULL as it doesn't strictly speaking have to be 0, and isn't on some ancient hardware that you'll probably never encounter.  (see this discussion: Can a conforming C implementation #define NULL to be something wacky)If I'm doing an end-of-string test in a loop, I use eitherchar *mystr = "this is a string";
int i;

for (i = 0; mystr[i] != '\0'; i++) {
/* do something with mystr[i] */
}orchar *mystr = "this is a string", *strp;

for (strp = mystr; *strp; strp++) {
/* do something with *strp */
}depending on whether I need the length later and how much the code needs to be fast (the second is slightly faster, which can matter in heavy string processing code).  They're both logically equivalent (at least as far as the string itself), both "legal C", and both portable.

What is difference between EMPTY and NULL string in Java?

Suppose you asked your friend to go to kitchen and check whether there are any chocolates inside the  Blue Snicker's box there.Your friend came back and may report one three results:1) Yes there are few chocolates inside the box.2) There are no chocolates in the box.3) There is no Blue Snicker's box in the kitchen.Now let us consider the similarity between 2) and 3) case. Suppose you asked your friend to bring a chocolate, he'll fail in both cases. However you may note that in 2nd case, it was because the box was empty, but in 3rd case it was because there was NO BOX in kitchen. It might be the case (in 3rd scenario) that you left the full  box in bedroom( thus he could not find the box in kitchen).Now the difference, If you give him a chocolate and ask him to put it inside that box. He will be able to do it in 2nd case, but not in third as there is NO box.Also that in second case, that empty box takes up some space in your kitchen despite the fact that its empty. It also weighs something though not as much as a box filled with chocolates.Now coming back to JAVA, String is like that Blue Snicker's box, its content are like those chocolates and kitchen is your program( or its reference tree) in which you are searching for that string.

AP computer science class definition help!?

Modifier methods are the methods that modify something like setName, setAuthor....
so there are 2 modifier methods in above code. Other methods like getAuthor, getTitle are called accessor methods.

for your question number 7, I and III cannot be a object for the class Book, because in your Book class, there is given that the parameters are (String, Int), which means there should be parameter inside it. So, (i) doesn't have any parameter, and (III) have String parameters but wrong Int parameter.

Answer to the question umber 8 is (B) and (E), because even if we leave blank, java will give out put as "null".

FOr question 9, answer is (C),

Why is a string always terminated with a null character?

A string is not always terminated with a null character.But I am conveniently assuming you are talking about C-strings, or null-terminated string, for which your question is correct. So when I am saying string henceforth, I mean of course C-strings.So when you declare a constant string likeconst char *s = “Hello!”;[math] [/math]A null character ‘\0’ is appended to the end of the string (C does it for you; you don’t need to explicitly add it, unless you’re working with some kind of a variable string) to let the code that works on your string where the end really is. For example, when printf() function is used on a null-terminated string, the characters are printed to the standard output until a null character (‘\0’) is encountered. If there was no null-character, the program will start to misbehave (probably print out some garbage value).Note that C strings are entirely different from other kinds of strings, like C++ strings, where the C++ Standard Template Library comes into play.

TRENDING NEWS