what is the output of this code and how? [closed] - c

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.
Program to understand sizeof operator:
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char *mess[]={ //array of pointers
"amol is a good boy",
"robin singh",
"genious boy",
"bitch please"
};
printf("%d",sizeof(mess)); // what does sizeof operator do?
}
Please explain the output of this code.

It is the storage size in bytes of 4 pointers to char.

You have your answer right in your question. It has a size of an array of pointers.
So the size is 4 * size of a pointer. (which is 32 on my system.) Your system might vary.

Related

Extracting bytes from a byte array one by one (C) [closed]

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.
I have a byte array (dB). I am trying to extract the bytes one by one. Why isn't this code working? Any pointers? Logically am I wrong? Or something wrong with my implementation?
You have byte buffers declared like this:
unsigned char *decodeBuf;
To read a single value from that buffer, at offset i you simply write:
unsigned char b = decodeBuf[i];
try
int main()
{
unsigned char tmp;
tmp = getByte(dB+dOffset); dOffset++;
}
it should work

How to convert a string containing a hex character code to the character value? [closed]

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.
I have an array of chars "0x55".
What I want to do is convert it to a char which is going to be U (because ASCII 0x55 = U).
So how to do this conversion?
#include <windows.h>
int main()
{
array[] = "0x55"
char test;
**// I want to move the string to that test to be one character which is U**
}
Any suggestions?
I think this is what you are after:
int main(int argc,char**argv)
{
char array[] = "0x55";
int value;
char test;
sscanf(array,"%x",&value);
test = value;
return 0;
}
In C++, I would code it a little differently, but this seems more like a C question.

What does the variable stores when it is assigned a printf statement in C [closed]

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.
void main(){
int i;
i=printf("how r u?\n");
i=printf("%d",i);
printf("%d",i);}
The above code gives the result as:
how r u?
91
My question:
How does stores 9 and 1??
From the man page: Upon successful return, these functions return the number of characters printed.... If an output error is encountered, a negative value is returned.
So you are getting 9 and i because printf wrote out 9 and 1 characters respectively.
This is also relevant: Why does printf return a value?

factorial using recursion+pointers [closed]

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 12 years ago.
i am learning C programming, i was trying to write a recursive function by using this prototype:
void fact(int *n);
The parameter of this function should be passed by reference. Thanks for your help.
I don't feel to be helpful in giving a complete solution -- this is just to show there is an answer:
void fact(int *n)
{
if (*n > 1)
{
int tmp = *n - 1;
fact(&tmp);
*n *= tmp;
}
}
I would never write a factorial function this way.

meaning of this code [closed]

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 12 years ago.
int main()
{
int x = 2, y = 6, z = 6;
x = y == z;
printf("%d", x);
}
== has higher precedence than =, and y==z is 1.
I will end the answer there, because this looks like homework.
http://codepad.org/fp4ZYJX5
The output is:
1
Have a look at this, which explains a similar, yet more complex question and will answer yours as well.
Output is 1
If you want more help we can give you

Resources