Questions tagged [int]

A data type that represents an integer. An integer is a whole number that can be negative, positive, or zero. (i.e. ...-2, -1, 0, 1, 2...) Use this tag for questions about using, storing, or manipulating integers.

int is a data type that represents an integer (a whole number - not a fraction).

int data types may vary based on:

  • the number of bits used to represent them - 16, 32, etc.
  • whether they allow both negative and positive values (signed integers) or only positive (unsigned integers).

In many (but not all) languages, integers are limited to a specific range due to the way they are stored - for instance, an ISO C 32-bit signed integer can store values from −2,147,483,648 to +2,147,483,647 (-2³¹ to 2³¹-1).

This keyword is often used in C-like languages (including C, C++, Golang, etc.)

9665 questions
3
votes
3 answers

subtracting characters of numbers

I am trying to understand what is going on with the code: cout << '5' - '3'; Is what I am printing an int? Why does it automatically change them to ints when I use the subtraction operator?
MS535
  • 47
  • 4
3
votes
2 answers

Why the Size of int specifically is 4 byte in C#?

The size of int is 2 byte in c and 4 in c#.why is that ?. Why not 2 byte like c. i searched on the web also but i've not found anything. I am searching for the real technical reason of this.
3
votes
7 answers

How to count from my new int value?

I had to calculate the price of a certain amount of tickets for like a theme park. The prices and amount of tickets has to be given by the user, but this is not my problem. My problem is that when the user enters 11 tickets he gets one free, the…
user3925079
3
votes
2 answers

How do I serialize IntEnum from enum34 to json in python?

I'm using the enum34 package and have managed to store objects subclassing Enum to json in a custom format. However, I have an object instance used quite a bit that subclasses IntEnum which doesn't seems to be picked up correctly by my custom…
3
votes
2 answers

Faster program when using long instead of int

I am trying to solve the following problem: Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. I submitted the following code which was rejected as too slow: public int…
quantum
  • 99
  • 1
  • 6
3
votes
3 answers

How can I specifically take out numbers in an integer, in C?

Lets say I have an integer called SIN and the scanf input receives 193456787. so SIN = 193456787; What I want to do is add up all the other numbers after the first digit. So 9 + 4 + 6 + 8 = 27 Can somebody please explain to a beginner how to do…
Derrick Rose
  • 664
  • 2
  • 9
  • 21
3
votes
3 answers

Conversion of a byte value into an int

I know that if we are performing arithmetic operations on byte value,then implicitly it is promoted to an int and the result will be an int,and hence we need to explicitly convert it into byte in order to store the result in a byte variable. But I…
Frosted Cupcake
  • 1,909
  • 2
  • 20
  • 42
3
votes
1 answer

Why does adding an int to this char array not add the ASCII character of the same value?

I've been working on a URLdecode function so I can parse POST requests received on an HTTP server, however I've ran into a hiccup. Whenever I add an integer to an array, it is not adding the integer's ASCII counterpart. Is there something I'm…
dylanweber
  • 580
  • 7
  • 19
3
votes
3 answers

Byte Operations and Datagrams in Java

I am trying to program a handshake type message as follows where C=Client S=Server: C-->S: "I'd like to talk" //session initiation S-->C: "80" //(n, randomly generated number) C-->S: "81" //(n+1) S: "does n= (n+1)-1?" //confirms the…
Matt Lick
  • 31
  • 2
3
votes
4 answers

How to generate a random integer using math.random class

I am having trouble with the RandInt() method as it will not return a random integer. The result must be an int ranged 0-9 and must use the math.random class. This is my code below: public class RandNumGenerator { public static int RandInt() { …
rico99
  • 77
  • 1
  • 3
  • 10
3
votes
1 answer

Integer Number too large in java int for the value 08 , but when I pass just 8 or 11,12,13 it is just fine

Employee("Helen",16000,1965,08,03),compiler is throwing the error that integer number is too large for value : 08 but compiler has no problem with value 11 or just 8. import java.util.*; class Employee{ private String name; …
PankajKushwaha
  • 878
  • 2
  • 11
  • 25
3
votes
2 answers

SWIFT: var someVariable:int = textfield.text.toInt() x textfield2.text.toInt() and force unwrap

First post here so please be gentle. Am fairly new to coding and am trying to get my head around SWIFT and its optionals. Would really appreciate some advice from the pros! I am writing a simple app whereby textfields are entered by the user and…
Slin S
  • 33
  • 3
3
votes
3 answers

read int with scanf until new line

I'm new to the c language and used java before, so I'm not so familiar with some things... I want to read an indefinite number of integer until there's a new line. I know, that new line is ⁄n and I already have a code, so the integer are read until…
bli77
  • 55
  • 1
  • 1
  • 5
3
votes
6 answers

Prevent user from inputting value larger than int max?

I have some cool code that takes an int value. I let my little brother test it, and what is the first thing he does? He enters this: 12345678910 And he got this error: User did not input a number. (Error Code 1) Well that's not true. Is there a…
DigiDuncan
  • 131
  • 1
  • 2
  • 11
3
votes
3 answers

swift forcing objective-c int to be assigned as Int32 then crashing

I have an objective c property that has been declared as @property int xmBufferSize; If I do sharedExample.xmBufferSize = 1024 it just works fine but when I am trying to set an integer value for that property from another variable var getThat:Int…
Mord Fustang
  • 1,523
  • 4
  • 40
  • 71
1 2 3
99
100