It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
For example in C, the NULL ('\0') stands for "nothing". And in mit-scheme the nil or the '() stands for nothing. So does Ruby use nil.
So i just wonder what's the symbol or variable that stands for "nothing" in other programming languages. thx.
You are wrong about C language NULL and '\0' being the same. Usually in C, NULL is used with pointers and '\0' is used with strings.
For example, The following code fragment compiles without any warning.
int *p=NULL;
char ch='\0';
But the following code gives you the warning "initialization makes integer from pointer without a cast" on compilation.
int *p='\0';
char ch=NULL;
So we can conclude that they are not equal and interchangeable.
Javascript: null
Python: None
It all depends from language developers preferences.
Everything in Ruby is object. nil is an object and empty string "" is also an object etc... But "" means 0 length string and nil means object with no reasonable value - in some situations it really is "nothing".
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
For example, I have a file, which says
char,5
int,6
Reading the above file, is it possible to declare 2 variable array in the code? So in future
if i add a new line it will automatically declare?
No, not in C.
You will need to write a script which reads this file and writes the c program.
In short, what you need is a C Source Code Generator.
Sure, just code exactly what you want. You can start with a structure that can hold either a character or an integer (with some boolean or integer to indicate which). Then you can allocate an array of them of any size.
When you read the first line, create an array of 5 such structures. Set their type variable to "char".
When you read the second lien, increase the size by 6. Set those six new ones to be integers.
And so on.
You can use an enum to track the type of each entry in the array. You can use a struct to hold the integer value, character value, (or just re-use the integer value) and type. You can make helper functions like isInteger, setIntegerValue, getCharacterValue, and so on.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
#include<stdio.h>
int main()
{
for(;NULL;)
printf("STACK");
return 0;
}
output: STACK
I know NULL have ascii value 0 and it's false, but when i run on turbo c, this program give output "STACK", how it is possible.
"STACK" is never outputted. This is because the conditional part of the for statement is always false (assuming NULL is #defined as (void *)0.
The turbo c compiler is ancient ( 20 years old). The behaviour you are seeing is a bug. The 16 bit application isn't running correctly on your OS ( Win7 ?).
As a workaround you can assign the NULL value to a variable and use that in the condition of the for loop, or even better switch to a newer compiler. Like wxdev-cpp
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
What is the meaning of "f" in C's printf?
The f in printf stands for formatted, its used for printing with formatted output.
As others have noted, the trailing f indicates formatted output (or formatted input for functions in the scanf family).
However, I'll add that the distinction matters because it's important for callers to know that the string is expected to have format-specifier semantics. For example, do not do this:
char* s = get_some_user_input();
printf(s); // WRONG. Instead use: printf("%s", s) or fputs(stdout, s)
If s happens to contain % characters, printing it directly with printf can cause it to access non-existent arguments, leading to undefined behavior (and this is a cause for some security vulnerabilities). Keep this naming convention in mind if you ever define your own printf-like variadic functions.
If I'm not mistaken, printf stands for "Print formatted data to stdout".
printf allows for formatting, while print doesnt. Also, print doesn't exist in C. I don't even know what printg is.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I just started in C programming and I know that "%d" defines that it will be a number value, as in:
int x = 9;
printf("X = %d", x);
getchar();
return 0;
but what are the other variable specifiers for C? (to define strings, and do they change for float, double, long, etc.?)
There's a good summary of the specifiers available at http://en.wikipedia.org/wiki/Printf_format_string#Format_placeholders .
Your question as phrased is meaningless. The %d is a format specifier, and has nothing to do with variable declarations.
If you were to google 'printf c', you would find many, many sites that answer your question.
You may want to pick up a copy of Kernighan and Ritchie's The C Programming Language. It short but fully packed. Working through this book is well worth the time.
But as to your question, you're asking about Format specifiers for string literals. You'll probably also want to look at escape characters soon (e.g. \n for new lines). Fortunately, it's all in K&R (the above book), specifically on page 153 (2nd edition).
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
ok guys,
this is a very good question in C code (not c++):
void *pName=function();
i'd like within "function()" to get the name of the pointer "pName", of course without passing it as an argument string to the same function.
and if you are really so good in C you can provide me the type of pointer, i mean for example:
char *pName=function();
i'd like to get name and type , so "pName" and "char" within the function.
thank you :)
This is not possible. The best you could do is write a macro (shudder) that passes the type and name as arguments to the function without you having to write them a second time.