In c programming what does the 'register' type do and when should it be used?
958875
"register" declares a variable to be stored in a CPU register rather than RAM.\n\nIt is a hangover from the olden days when the memory CPU bus interface was slow by todays standards. It allowed for faster execution by storing a variable directly into a CPU register instead of RAM eliminating the data fetch execute cycle associated with decoding the address of the data and moving the data in and out of a CPU  register.\n\nThis type is more or less defunct in modern C programming. One of the mostly widely used compilers Microsofts Visual C++ no longer implements this, although it still supports the declaration for backward compatibility. \n\nIn fact when it sees a register variable it just converts it into a normal variable store in RAM. In MS Visual C++ you can even use & on a register variable to get its address which you shouldn't be able to do in ANSI C as an internal CPU register has no address! \n\nModern compilers like Visual C++  automatically use CPU registers if the relevant optimisation is turned on in the compiler flags. Therfore there is no longer any requirements for the programmer to implement low level optimisation using register variables. You could use any alternate data type that suits your needs. e.g. (short) int, long
201573
void anyfun(void);\nvoid anyfun();\n\nTechnically, the above are the same. The compiler will assume an empty parameter list to mean (void). Thus, the above are the same. Style-wise, the latter of the two is preferred for C++ programming.\n\nvoid anyfun(void);\nanyfun();\n\nThe compiler will assume you want to have no parameters, but it will also *assume* you will return a value of type "int". The compiler will have to do something for the return since you did not specify a type, and it chooses int as the return type for the function. This is just not good style and should be avoided in all cases.\n\nvoid anyfun(void);\nanyfun(void);\n\nAgain, the compiler is going to respect your (void) parameter list, but will supply the default "int" return type. This should be avoided in all cases. It is always good style and proper programming practice to *always* specify the return type of a function, especially if you don't intend to reutrn anything.\n\nYour first function declaration:\n\nvoid anyfun(void);\n\nis the best style and most commonly accepted style-wise. Always specify the return type of a function. Parameters are optional and () is proper style in C++ if you don't have parameters.
943372
u have to ponit it or use\n\nthese are the 2 way's:\n\n#include <iostream>\nusing namespcae std;\nint main()\n{\nint num[8];\nint index;\n\nnum[0] = 42;\nnum[1] = 2001;\nnum[2] = 7;\nnum[3] = 180;\nnum[4] = 99;\nnum[5] = 1993;\n\nfor(index = 0; index <= 5; index++)\n{\nstd::cout<< index[num] << endl;\n}\n system("pause");\nreturn 0;\n}\n\nor\n\n#include <iostream>\n#define MAX 20\nusing namespcae std;\n\nint main()\n{\n\nint a[MAX] = {23,43,4,5,34,343,12,14};\nint b;\n\ncout.setf(ios::right);\n\nfor(b = 0; b < MAX; b++){\n\ncout << endl << endl;\n\ncout << "The Elemnt in ";\n\ncout.width(2);\n\ncout << (b +1) << " is ";\n\ncout.width(2);\n\nstd::cout << b[a];\n}\nreturn 0;\n}
461539
printf("%-15u&#92;n",40000);\n\nprovided I understood it correctly.
1018747
You can store as many characters in an C array as you want.\n\nAlso I suggest you change to djgpp if you something similar to turbo c++. TUrbo C++ 3 is more or less dead and was ment for DOS only. Other alternates are VC 6, GCC on Linux, GCC using cygwin on windows.\n\nThere are some errors in the code you posted along with your question.\n\nIt should be \n\nchar input[1000];\ngets(input);\n\nand not gets(&input)\nSame is the case with scanf\n\nSince the name of an arrey itself is a pointer you need not send address of pointer.
386448
In traditional Dos based systems it is a simple matter of including relevant assembly code in C language. May not be so easy if you are in applicaton mode on other operating systems. Not very difficult, need to know assembly language if you want to directly manipulate, other you can use operating system routines to access it (if your program resides within the kernel).
653205
It lets the linker help the compiler piece together code that is in other files/libraries - for instance, if you do:\n\n#include <iostream>\n\nYou're going to be able to use the functions within the iostream library - otherwise, it wouldn't know where to go to get those function definitions.
52818
Wow, 17 years of C programming, and I didn't know that one.  I did some looking and according to the man page on scanf:\n\n[ Matches a nonempty sequence of characters from  the\n  specified  set  of  accepted  characters;  the next\n  pointer must be a pointer to char, and  there  must\n  be  enough  room  for  all  the  characters  in the\n  string, plus  a  terminating  NUL  character.   The\n  usual  skip  of  leading white space is suppressed.\n  The string is to be made up of  characters  in  (or\n  not in) a particular set; the set is defined by the\n  characters between the open bracket [ character and\n  a  close  bracket  ]  character.   The set excludes\n  those characters if the first character  after  the\n  open bracket is a circumflex ^.  To include a close\n  bracket in the set, make  it  the  first  character\n  after the open bracket or the circumflex; any other\n  position will end the set.  The hyphen character  -\n  is  also  special;  when  placed  between two other\n  characters, it adds all intervening  characters  to\n  the  set.   To  include  a hyphen, make it the last\n  character before  the  final  close  bracket.   For\n  instance,  `[^]0-9-]'  means  the  set  `everything\n  except  close  bracket,  zero  through  nine,   and\n  hyphen'.   The string ends with the appearance of a\n  character not in the (or, with  a  circumflex,  in)\n  set or when the field width runs out.\n\nSo, I interpret this as read everything up until the terminating newline.  Since the man page says the next argument must be a character pointer, the entire sequence is read as a string.\n\nFor what it's worth, I don't use scanf.  I use gets or fgets, and if I really need scanf, I then use sscanf on what was read by gets or fgets.
1028984
C does not have a boolean data type as in the case of Visual Basic or any other SDK.\nSo, you can't declare a variable like:\n\nbool flag; (wrong)\n\nBut, instead you can do this alternative, using preprocessor directive(#)\n\n#define TRUE 1\n#define FALSE 0\n\nint main()\n{\n    ...\n    ...\n   return 0;\n}\n\nYou can now use the keyword 'TRUE' and 'FALSE' like this:\nif(x = TRUE)\n{\n  ...\n  ...\n}\nelse\n{\n  ...\n  ...\n}\n\nTRUE and FALSE technically are called Symbolic Constants
192550
Do you have a description of the actual datapath?   It's probably in the engineering manual for the chip.\n\nIf not, you'll have to design it:  Start with all the visible registers and figure out what is necessary to implement all of the instructions in the instruction set.   For example, if there's an instruction which adds the number in one register to the number in another register and places the result in a 3rd register, that pretty much defines PART of the data path.   You'll need to add to that the operations (complement, shift, subtract, ...) for all the other instructions.\n\nOnce you've done that, it should be pretty straightforward to write a C or C++ program to simulate it.
799772
Well you should be asking how to create the C language? If you have worked in the C language, it is not just the IDE you see. There are libraries and other files you have to take care of - most importantly the compiler.\n\nAs you know the compiler should be able to do two things. First, verify the code and syntax. This includes checking if all variables have been declared and stuff, and finally give out proper error messages. Secondly, it should convert all the source code to assembly language.\n\nThe IDE is just one part. It somehow combines all these operations into one task. You can design your own IDE; make it the way you want, but it requires knowledge about how to communicate with the components and capture their outputs, and finally present them?\n\nI've told you everything except designing the compiler. If you want to design the compiler you should know the assembly language. The exact info that goes into building the compiler is a mystery to me though. I am not a computer engineer myself, but nevertheless computers interest me. What I would suggest is try out the wikipedia link related to the C language; and then post questions in forums and try to obtain the expected services required by a compiler. This should give you some idea. But I don't know where to start you off on that one.\n\nOnce you find the requirements designing the compiler won't be a problem for you. But I must warn you about licences. In spite of C being an old language, I don't know if anyone tried coming out with their own versions. I mean to say is I don't know if anyone tried to design the exact same thing. It could violate some licences. So be careful.
242005
/*set up a struct like so:*/\n#include <stdlib.h>\n#include <stdio.h>\n\nint main()\n{\n\nstruct person\n{\n  char name[30], address[50];\n  int age,telephone;\n};\n\n/*variable of type persons*/\n struct person details;\n\n/*read*/\n printf("Name:");\n fgets(details.name, 30,stdin);\n\n printf("Address:");\n fgets(details.address,50,stdin);\n\n printf("Age:");\n scanf("%d",&(details.age));\n\n printf("Number:");\nscanf("%d",&(details.telephone));\n\n/*print*/\n printf("&#92;nprinting data");\nprintf("Name: %s",(details.name));\nprintf("Address: %s",(details.address));\nprintf("Age: %d&#92;n",(details.age));\nprintf("Number: %d&#92;n",(details.telephone));\n\nreturn 0;\n}\n\n\n/* subtle things to note, use fgets when someone might include a space in their input, but remember fgets will store the &#92;n character, so keep that in mind when printing it */
116319
In C, "void" has three distinct uses.\n\n1) Return values for functions. If a function returns literally NOTHING, then it is declared as returning void. This tells the compiler not to push/pop any return value on/off the stack on return. It also tells the compiler that the result of the function cannot be assigned or compared to any variable.\n\n2) Generic pointers. When you are dealing with generic pointers, such as returns from "malloc", parameters to "free", "memcpy" and such, these functions need pointers, but they really don't care what data type the pointers actually point to. Rather than declaring a copy of these functions that returns every possible atomic type (char, short, int, long, float, double and such), they simply use a pointer to type void (void*) instead.\n\n3) Ignoring return values. If you are using a particularly picky compiler, or even a program such as Lint that produces warnings when you ignore the return value of a function that returns something other than void, you can cast the function call to type void to make the warning go away if you really don't need to know the return value.\n\nFor instance, "printf" returns an "int" value. So if you use the following line in your program:\n\nprintf ("Hello world");\n\nit could actually generate a warning, since you ignore the return value. If instead you use the line\n\n(void) printf ("Hello world");\n\nyou are telling the compiler that you are purposefully ignoring the return value, so it will not issue a warning in this case. This is of particular use if you have a policy of zero warnings (as all programmers should).\n\n"Void" kind of lives in limbo just outside of datatypes - it is not a modifier such as "static", "const" or "volatile", but it is not possible to declare a variable of type "void". It is kind of in its own little world there.
158838
I believe that modulo "%" is an integer operator. For floating point numbers, you should use the function "fmod", which is a standard function whose prototype is in math.h.\n\nFloating point is useful for a number of things, typically:\n\n- where fractional information is required (although using fixed point arithmetic can suffice here too)\n\n- where overflow is possible, such as if your long is only 32 bits, and your result may be larger than 2^31 - 1\n\nThe float *should* work - perhaps there is a problem with your declaration, or even possibly your compiler (sometimes happens). It is frustrating learning how to program in C and takes quite a while to master - that is why I always laugh at the "Learn C in 24 hours" books.
898215
As you probably know the registers are of 16 bit width in 8086.All definitions are based on that width.\n\nOverflow Flag (OF) - set if the result is too large positive number, or is too small negative number to fit into destination operand:- This means that it cannot fit into the required bit-width, hence literally overflows out.\nthe flag is set for such situations.\n\nOverflow Flag (OF) - set to 1 when there is a signed overflow. For example, when you add bytes 100 + 50 (result is not in range -128...127). during unsigned operations , this has no meaning. even if it's set it's not to be considered.\n\n\n\nCarry Flag (CF) - set if there was a carry from or borrow to the most significant bit during last result calculation.\n( this is used in add/sub operations)\nalternative but better definition:-\nCarry Flag (CF) - this flag is set to 1 when there is an unsigned overflow. For example when you add bytes 255 + 1 (result is not in range 0...255). When there is no overflow this flag is set to 0.\n\n\nAlso the field address in the status register varies. check out\nhttp://www.emu8086.com/assembly_language_tutorial_assembler_reference/flags.gif\nfor the exact locations
625434
My guess is that a lot of the basics are going to be hit.\nReview standard entry and exit, and the special applications of instructions:\n LA to increment a register\n BCTR and BXLE for loops\n SR to zero a register\n XR (and XC) to swap registers (or memory locations)\n TRT for a fast character search\n EX with \n BALR for subroutine entry\n CVB and CVD (on a guess)\n TM and TS\n ED and EDMK\n\n\nDon't know what you've covered, but drop me a line if you've got questions. I used to do 360/370 assembler for a living, up till the late '80's.
577652
Since you specified that the language is "C", it's\nworth pointing out that the Ansi standard guarantees\nthat the implementation will include a "qsort" function.\n\nAll you need to do is write the simple comparison\nfunction which is passed to qsort, and you're done.\n\nI copied the following (including the little test program)\ndirectly from the qsort man page:\n\n#include <stdlib.h>\n#include <stdio.h>\n\nstatic int\nintcompare(const void *p1, const void *p2)\n{\n  int i = *((int *)p1);\n  int j = *((int *)p2);\n\n  if (i > j)\n    return (1);\n  if (i < j)\n    return (-1);\n  return (0);\n}\n\nint\nmain()\n{\n  int i;\n  int a[10] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };\n  size_t nelems = sizeof (a) / sizeof (int);\n\n  qsort((void *)a, nelems, sizeof (int), intcompare);\n\n  for (i = 0; i < nelems; i++)\n    (void) printf("%d ", a[i]);\n\n  (void) printf("&#92;n");\n  return (0);\n}\n\n\nSee the references for the man page as well as the\nsource from the OpenSolaris site.